'vbscript - SQL Windows Authentication - different user

I want to read data from an SQL Database in my VBS Script. My problem: I need to logon with Windows Authentication and not with an SQL Account. But I cannot use

ConnectionString ="Driver={SQL Server};Server=myLocalServer; Database=myDb;trusted_connection=yes;"

because I do not want to use my Windows Account to logon. I do not have the permission. I need to open the connection with a different Windows User.

How can I do that? Using UID and PWD is only for SQL Accounts as far as I know.



Solution 1:[1]

ADODB should work.

Dim objConn As ADODB.Connection : Set objConn = New ADODB.Connection
Dim objRs As ADODB.Recordset : Set objRs = New ADODB.Recordset
Dim strSQL As String

objConn.ConnectionString = "Provider=SQLOLEDB;" & _
                           "Data Source=servername.contoso.com;" & _
                           "Initial Catalog=database;" & _
                           "User [email protected];" & _
                           "Password=lmaocleartextpassword;"

objConn.Open

strSQL = "SELECT * FROM Database.dbo.Table Where BlahBlah"

Set objRS.ActiveConnection = objConn
objRs.Open strSQL

' Do stuff with objRs data

objConn.Close
Set objRs = Nothing
Set objConn = Nothing

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lucretius