Reputation: 8148
I'm diong a typical Windows Integrated Connection from a .Net Winforms Application:
Dim sqlConnetion As New SqlConnection("Server=jupiter;Database=io;Integrated Security=True;") sqlConnetion.Open()
I keep getting the following error:
Cannot open database "io" requested by the login. The login failed. Login failed for user 'MARS\viking'.
I've also tried the following connection string variations with the same results:
Data Source=jupiter;Initial Catalog=io;Integrated Security=True;
Data Source=MSSGDEV;Initial Catalog=MSSQLSERVER;Integrated Security=SSPI;
The wierd thing is I can connect to the db using the SQL Management Studio with the same user from the same computer using integrated security. Is there a bug in my connection code? Or is there some special configuration setting on the SQL server I must set to allow connections from code?
Upvotes: 1
Views: 629
Reputation: 8148
A coworker finally found the answer. I'd put the sql server instance (there are two sql server instances on my server) in the slot where the database name belonged. . . Thanks all for taking your time to help figure this out.
Upvotes: 0
Reputation: 11
Edited my answer (since the question was updated):
You need to change "Integrated Security=True;" to "Integrated Security=SSPI" or "Trusted_Connection=True"
(note the underscore in "Trusted_Connection")
Upvotes: 1
Reputation: 95133
Try "Data Source=jupiter;Initial Catalog=io;Integrated Security=True;" instead. If you use Integrated Security, you have to use Data Source/Initial Catalog. If you use Trusted_Connection, you can use Server/Database. ConnectionStrings.com is fantastic.
Upvotes: 3