Good morning,
I try to connect to SQL Server using VBA. I used
sConnect = "ODBC;DRIVER=SQL Server;SERVER=XXXXX;DATABASE=" & Antwort
sConnect = sConnect & ";" & sUsername & ";" & sPassword
Set td = CurrentDb.CreateTableDef("dbo_" & sTabNames(i), dbAttachSavePWD, "dbo." & sTabNames(i), sConnect)
CurrentDb.TableDefs.Append td
SQL Server setup is: Windows Authentification Login, say val232 (Administrator), and another Login with restricted access, say User / Userpw. This User is the one used in the VBA connection string.
By restricted access is meant: the user User/Userpwcan is granted "Select" data but cannot change the database content (=ReadOnly).
What works:
- Connection to SQL Server and access to the database through MS Management Studio using Windows Authentification val232
- Connection to SQL Server and access to the database through MS Management Studio using User/Userpw ("Select" only).
- Connection to SQL Server and the database through MS Access / VBA on a computer logged in as val232 and VBA sUsername=User and sPassword=Userpw.
- Connecting to the database through MS Access manually: External data --> ODBC Database with User/Userpw being logged as val232 or YYYY (= any arbitrary Windows Login) !
What does not work
- Connection to SQL Server and the database through MS Access / VBA on a computer logged in as YYYY and VBA sUsername User and sPassword Userpw.
Error message in Server Log file is :
State 11
Reason: Token-based server access validation failed with an infrastructure error. Check for previous errors. [CLIENT: 192.168.2.161]
In MS Access is the mysterious part. The error says[Microsoft][ODBC SQL SERVER DRIVER][SQL SERVER]Login failed for user ''YYYY'. The points is that the Windows Login YYYY is not used in the connection string of the VBA Code !!!!
So I suspect that MS Windows (MS Access? ODBC?) used the Windows Authentication in the background for whatever purpose to create the connection. I setup (as an experiment) in the SQL SERVER, Security Login YYYY and the new error message in the Server Error
Log is
State 38
Login failed for user YYYY. Reason: Failed to open the explicitly specified database. [CLIENT: 192.168.2.161]
Well fine but I would like to connect to SQL Server from MS Access / VBA using User/Userpw independently from the Windows Login ...
and I do not want to give all Windows Login "full" permission on the SQL Server as well as for the User/userpw(it should stay readonly !).
Any help would be greatly appreciated to
1) understand the function of the Windows Login in the connection through VBA
2) find a solution to connect independently from the Windows Login using Ms Access / VBA
Thank you very much for any clues or ideas
(MS Windows is XP 32 bits or Win7 32 bits; Access is 2010 32 bits; Server is 2008R2 64bits)