Reputation: 385
I am working on a existing MS Access 2010 project that has a linked table link to Sql Server database.
When I mouse over to the linked table I can see a connection string 'ODBC;DRIVER=SQL Server;SERVER=10.0.0.1;UID=testdb;APP=Microsoft Office 2003;WSID=abc;TABLE=dbo.user'
This looks like a dsn-less linked table.
Question
Where the connect string locate at? How to change it (example database name)?
How can I create a similar dsn-less linked table? Anytime when I create a linked table Access 2010 always force me to choose\create a dsn (file or machine).
Upvotes: 24
Views: 91264
Reputation: 91376
To print all connection strings:
Dim tdf As TableDef
Dim db As Database
Set db = CurrentDb
For Each tdf In CurrentDb.TableDefs
If tdf.Connect <> vbNullString Then
Debug.Print tdf.Name; " -- "; tdf.SourceTableName; " -- "; tdf.Connect
End If
Next
To create a linked table:
With CurrentDb
''If the table does not have a unique index, you will need to create one
''if you wish to update.
Set tdf = .CreateTableDef("LocalName")
tdf.Connect = "ODBC;DRIVER=SQL Server;SERVER=10.0.0.1;" _
& "UID=testdb;APP=Microsoft Office 2003;WSID=abc;TABLE=dbo.user"
tdf.SourceTableName = "TABLE_NAME"
.TableDefs.Append tdf
.TableDefs.Refresh
End With
To change a link:
Set db = CurrentDB
Set tdf = db.TableDefs("MyTable")
tdf.Connect = "ODBC;DRIVER=SQL Server;SERVER=10.0.0.1;" _
& "UID=testdb;APP=Microsoft Office 2003;WSID=abc;TABLE=dbo.user"
tdf.RefreshLink
Upvotes: 35
Reputation: 1442
You can change the connection string using the following guide (Original Source).
Firstly, get the existing connection string.
Secondly update the connection string.
Upvotes: 26