I'm having problems getting my DB to Link to different SQL servers. I got it to work fine on my own machine, but when distributed it at the client, and to another office, the Link didn't work. It either timed out, or gave errors.
I created a LinkTables Method (below) that would allow me to distribute the DB to the client running on another server. I created a local Settings table to store the Connection Strings of different locations. I wanted to either use a DSN file, or connect completely through code. I didn't want to setup System/User ODBC connections on anybody's machine. Unfortunately, I wasn't the one testing it out, but for some reason the tech could not get connected to SQL, without setup up a System ODBC manually. That's the reason I changed to ADP, because it was easier to connect.
Anyway, here's my code, and Test Connection String. Anyone have comments why this would not work? Also, what is required in the Connection String?
Thanks.
I created a LinkTables Method (below) that would allow me to distribute the DB to the client running on another server. I created a local Settings table to store the Connection Strings of different locations. I wanted to either use a DSN file, or connect completely through code. I didn't want to setup System/User ODBC connections on anybody's machine. Unfortunately, I wasn't the one testing it out, but for some reason the tech could not get connected to SQL, without setup up a System ODBC manually. That's the reason I changed to ADP, because it was easier to connect.
Anyway, here's my code, and Test Connection String. Anyone have comments why this would not work? Also, what is required in the Connection String?
Thanks.
Code:
Public Sub LinkTables() Dim DBPath As String Dim DBPath2 As String Dim TCPath As String Dim tds As TableDefs Dim td As TableDef Dim x, y, p As Integer Dim s, c As String On Error GoTo Error DBPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")) On Error Resume Next If gLocation = "" Then Exit Sub c = DLookup("ConnStr", "Settings", "ID = '" & gLocation & "'") If c = "" Then Exit Sub On Error GoTo Error ' Test Connection c = "ODBC;DRIVER=SQL Server;UID=user;PWD=pass;SERVER=CORPMAT;DATABASE=AuditTest" Set tds = CurrentDb.TableDefs y = tds.Count For x = 0 To y - 1 Set td = tds(x) s = td.Connect If Left(s, 4) = "ODBC" Then ' Check for SQL Link ' If Left(s, 9) = ";DATABASE" Then ' Check for MDB Link td.Connect = c td.RefreshLink End If Next MsgBox "Tables Linked Successfully." leave: Set tds = Nothing Set td = Nothing Exit Sub Error: MsgBox "Error Linking Tables! " + Error$, vbCritical Resume leave End Sub
Comment