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?

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;"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.