I've written a function that syncs a database to a sql server.
My problem is: (it's not actually a problem. I simply need to know why)
Even though re-linking and adding linked tables/views are done with the same connection string, After running the function, Linked Table Manager shows two data source.
One contains the re-linked objects, the other contains added objects.
And if I check their connection string they are different.
Relinked object show:
Added objects show:
Both are working without problem.
Does anyone know why the connection strings are different?
Thanks.
- It connects to a sql server and opens a recordset of all tables and views in the sql server.
If it finds a linked table/view in CurrentDB, re-links and refreshes the connection string.
if it doesn't find a linked table/view, adds a new linked table/view. - And then deletes all other tables/views in CurrentDB.
SQL:
stConnect = "ODBC;DRIVER=ODBC Driver 18 for SQL Server;SERVER=Server;DATABASE=MyDatabase;Trusted_Connection=Yes;Encrypt=no;"
Do
tbl = rs.Fields("name")
If DCount("[Name]", "MSysObjects", "[Name] = '" & tbl & "'") = 1 Then
db.TableDefs(tbl).Connect = stConnect
db.TableDefs(tbl).RefreshLink
Else
DoCmd.TransferDatabase acLink, "ODBC Database", stConnect, acTable, tbl, tbl
End If
DoEvents
rs.MoveNext
Loop Until rs.EOF
My problem is: (it's not actually a problem. I simply need to know why)
Even though re-linking and adding linked tables/views are done with the same connection string, After running the function, Linked Table Manager shows two data source.
One contains the re-linked objects, the other contains added objects.
And if I check their connection string they are different.
Relinked object show:
Added objects show:
Both are working without problem.
Does anyone know why the connection strings are different?
Thanks.