I'm trying to create linked tables to SQL Server tables in MS Access via a VBA script. Currently, I have the following, which works perfectly:
strConnect = "ODBC;DSN=xxx;Trusted_Connection=Yes;" & _
"APP=Microsoft Office;DATABASE=myDB;ApplicationIntent=READONLY;"
aSourceTable = Array("dmy.Tab1", "dmy.Tab2", "dmy.Tab3", "dmy.Tab4")
For X = 0 To UBound(aSourceTable)
Set t = New TableDef
t.Connect = strConnect
t.NAME = Replace(aSourceTable(X), "dmy.", "") ' remove schema
t.SourceTableName = aSourceTable(X)
CurrentDb.TableDefs.Append t
Next X
Where xxx is the data server name and myDB is the database I want to connect to.
Now I'm trying to recreate the same linked tables, but the ODBC connection to the SQL server has to go through an application role (which already has been created in SQL). Any ideas on how to go about this? I've tried populating the UID/Password parameter in the connection string, but that doesn't seem to work.
I've already created the application role:
Name - tempapprole
Pwd - temppassword
Many thanks,
Nick
sp_setapproleafter you connect. Do you know how to run stored procedure in your code? docs.microsoft.com/en-us/sql/relational-databases/… - Nick.McDermaidsp_setapproleis really not that secure given that it's in clear text in your code. - Nick.McDermaid