Question SQL Connection string ignoring UserID Pin

ashton83

New member
Joined
Jan 23, 2018
Messages
1
Programming Experience
3-5
Using the code below to connect to a SQL server and for half the users it connects using the user "john" from the query string and connects fine but others its using the same query string but ignores the userID and uses their windows id instead.

Has anyone else come across this and why it ignores the userID?

Thanks,

John

using (SqlConnection connection = new SqlConnection("Data Source=sqlServer;Database=dbName;User Id=john;Password=pass123;"))
{
connection.Open();
// Do work here; connection closed on following line.
connection.Close();
}

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection(v=vs.110).aspx
 
I wouldn't have thought it would be necessary by try adding "Integrated Security=False".

By the way, there's no need to explicitly close the connection when you create it with a 'using' statement. The connection is disposed, and therefore closed, at the end of the block. That's exactly why you use a 'using' statement.
 
Back
Top Bottom