How to impersonate another Windows login in an ADODB connection?

JorgeX

New Member
How do I via an ADODB.Connection object connect to a MS SQL Server using a specified set of Windows credentials?Example:\[code\]Dim oConn Set oConn = CreateObject("ADODB.Connection")Dim oRsSet oRs = CreateObject("ADODB.Recordset")Dim strConnectionDim strSQLstrSQL = "SELECT * from Computer WHERE DeviceName = N'myDevice'"oConn.Provider = "SQLOLEDB.1"oConn.Properties("User ID") = "myDomain\myUser" oConn.Properties("Password") = "myPassword" oConn.Properties("Initial Catalog") = "myDB"oConn.Properties("Data Source") = "mySQLServer"oConn.Open\[/code\]If I do like that, then it fails with the error below:\[code\]Microsoft OLE DB Provider for SQL Server error '80040e4d' Login failed for user 'myDomain\myUser'.\[/code\]Checking the SQL Server log shows this error:\[code\]Login failed for user 'myDomain\myUser'. Reason: Could not find a login matching the name provided. [CLIENT: <IP>]\[/code\]The account "myDomain\myUser" has access to the SQL Server as it's a member of a group that has "sysadmin" privileges on the server. I can RDP to the SQL Server using the same username and successfully open Management Studio and manage the SQL Server.What I essentially would like to achieve is to use integrated security as I'm running this via a web page on IIS where you have to authenticate using Active Directory to get access. The authentication part is working, and \[code\]Request.ServerVariables("AUTH_USER")\[/code\] will show the correct username.If I replace the "User ID" and "Password" part with \[code\]oConn.Properties("Integrated Security") = "SSPI"\[/code\] then I get the error below:\[code\]Microsoft OLE DB Provider for SQL Server error '80040e4d' Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.\[/code\]Which isn't my supplied credentials?How can I make this work?Thanks in advance.
 
Back
Top