views:

208

answers:

3

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?

+2  A: 

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.

Eric
Same error. :-(
Jeff
Can you open that database with the login? It seems to be failing on the DB, not the server itself.
Eric
That is correct. That's what makes it wierd--I can connect to that DB, with the same user, etc using SQL Management studio no problem.
Jeff
+1  A: 

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")

Brendan Green
sorry, that was a typo. It should have said: Cannot open database "io" requested...
Jeff
I tried the SSPI varient with the same result :-(
Jeff
A: 

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.

Jeff