I am trying to run a stored procedure (using Access VBA) in the SQL database. I can find a few examples of this on SO and on other sites but what I am unable to find is connection string where I can provide my login details as windows authentication won't work because I have to use a different user to connect to SQL database
Here is what I have tried so far (got this from one of the post in SO, unfortunately, I can't find the post anymore):
Sub RunSQLProc()
Dim cdb As DAO.Database, qdf As DAO.QueryDef
Set cdb = CurrentDb
Set qdf = cdb.CreateQueryDef("")
qdf.Connect = "ODBC;" & _
"Driver=SQL Server;" & _
"Server=myServer;" & _
"Database=myDatabase;" & _
"UID=myUsername;" & _
"PWD=myPassword;" & _
"Trusted_Connection=yes;"
' "Driver={SQL Server Native Client 11.0};" & _
' "MARS Connection=True;"
qdf.SQL = "SQLStroedProcedure;"
qdf.ReturnsRecords = False
qdf.Execute dbFailOnError '<-- this line throws the error
Set qdf = Nothing
Set cdb = Nothing
End Sub
On qdf.Execute dbFailOnError line, I get the following error:
Run-time error '3151': ODBC--connection to 'SQL ServermyServer'failed.
I have managed to connect to the SQL database and run the stored procedure through SQL Server Management Studio. This tells me that the details in my connection string are correct (although I haven't provided the actual details here) but I suspect there is an issue with my connection string.
Happy to provide more details. Any help is much appreciated, thanks
P.S. Apologies for my lack of knowledge in Access. I just don't use it very often