Reputation: 129
Hey guys I have what should be a simple question, but I am new to C# so I am having just a little problem. I am using the following connection:
SqlConnection conn = new SqlConnection(@"Server=myservername\SQLEXPRESS;Database=Names;");
I have also tried to include user id and password but my login always fails.
I think this is because I am not really sure what username and password to use.
With my sql server I am using windows authentication... if that helps.
does anyone know which username and password I should be using? or another way to do this?
I have seen that I may need to turn remote access on in my sql settings, can anyone tell me how to do that?
Thanks!
Upvotes: 2
Views: 426
Reputation: 60190
Your connection string should specify that integrated authentication (Windows authentication) has to be used. Otherwise it tries to do SQL user/password authentication, which is disabled on the SQL Server by default, and if enabled it doesn't authenticate against Windows users.
Server=.\SQLEXPRESS;Database=YourDatabaseName;Integrated Security=SSPI;
Remote access is only required if your application and the SQL Server Express instance aren't on the same machine (which is why the sample connection string here has a .
for the server name, which represents the local server).
Upvotes: 4