Microsoft
Software
Hardware
Network
Question : Link SQL Table using DSN or DSNless
having some problems with my database. It is semi urgent.
I have an Access97 database and SQL 2000. I'm trying to accomplish 1 or 2 things. I would like to connect to the SQL database called "test" and link the "openord" table in there to the access db. I do not want to setup an ODBC at every computer so I want to do it in a module.
Here is what I have so far but I'm getting errors.
__________________________
__________
__________
______
Function CreateDSNConnection()
On Error GoTo CreateDSNConnection_Err
Dim stConnect As String
stConnect = "Driver={SQL Server};Server=servername;
Database=t
est;Uid=us
er;Pwd=pas
sword;"
DBEngine.RegisterDatabase "proddata", "SQL Server", True, stConnect
CreateDSNConnection = True
Exit Function
CreateDSNConnection_Err:
CreateDSNConnection = False
MsgBox "CreateDSNConnection encountered an unexpected error: " & Err.Description
End Function
__________________________
__________
__________
____
That code right there gives me "ODBC Call failed". But I know the username and password I'm trying works because I can create the DSN manually. If I can manage to create the DSN, I'll manually link the table in SQL and use this code in the autoexec or something.
Now, here is the other way I'm trying to do it.
__________________________
________
Function linktbl()
Dim DBconnect As Object
Dim CnnStr As String
Dim MyDb As Database
Dim tdf As TableDef
CnnStr = "Provider=sqloledb;" & _
"Data Source=servername;" & _
"Initial Catalog=test;" & _
"User ID=user;password=password;
"
Set DBconnect = CreateObject("ADODB.Connec
tion")
DBconnect.ConnectionString
= CnnStr
Set MyDb = CurrentDb
Set tdf = MyDb.CreateTableDef("openo
rd", dbAttachSavePWD, "openord", CnnStr)
MyDb.TableDefs.Append tdf
MyDb.TableDefs.Refresh
End Function
__________________________
__________
_________
This code gets down to the "mydb.tabledefs.append" line and gives me an error "Couldn't find installable ISAM".
I'm lost and desperate at this point. I have limited programming knowledge but willing to try anything. I've been to many websites and looked at pages of code but don't imagine I need all of it to do something so simple. Infact the code I posted here was taken from a few of those sites. HELP! :)
Answer : Link SQL Table using DSN or DSNless
PAQed with points refunded (250)
Computer101
EE Admin
Random Solutions
Visual Studio 2008 SP1 Install Issue
Windows SharePoint Services Search Required on Farm, not running Stopping
OCS Federated Contacts DO NOT show presence?
Cannot joining a Windows server 2008 domain from xp computer
Convert from VMWare to Hyper-V
adding routes between two netkorks
XP Safe Mode Boot Hangs on hpdskflt.sys
VB:NET MSSQL problem write "strings" InsertCommand
how to open, review, and edit a .exe file?
How to Set Default Domain Controller? SBS 2003 / Exchange 2007