I am trying to connect to a sql server using login which accepts the username and password, instead of storing the credentials in the connection string.
But whenevr I pass the variable in the connection string I am getting an error which says login failed for the user. Is it possible to pass variables in the connection string?

The connection string is:

strSQLconn = "Driver={SQL Server};Server=Servername;Database=dbname;" & _
"Uid=username;Pwd=& strPw;"
objSQLconn.Open strSQLconn

strPw is the variable in which I am storing the password.
It works fine when I do it without the login form.

Can anyone tell me why this error is showing up?

9 Years
Discussion Span
Last Post by thewebhostingdi

I am a little rusty at this but i think if you change the uid and pwd to "Uid=" & username & ";pwd=" & strPw & ";" you should have it


You can dynamically render the connection string according to the username and password supplied in the form.

strSQLconn = "Driver={SQL Server};Server=Servername;Database=dbname;" & _
"Uid=" & strusername & ";Pwd=& strPw;"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.