views:

286

answers:

5

Hi, I am sorry if this sounds like a silly question, but I have googled for a while for a solution and no success. I am trying to establish a connection from VS 2008 to SQL Server. I am trying to use an user that my web application has been successfuly using to access the database from in its connection string. But when doing it from VS 2008, it tells me "Login failed for use 'xxxxxx'". I am currently in the "Add Connection" window. I have chosen the datasource and server name, fulfilled username and password for SQL Server Authentication. Do I have to set specific permissions for this user? Do I need to allow a VS 2008 user in SQL Server? Thanks.

A: 

Do you have SQL Server Management Studio Express Installed? if so try connecting as the same user through that interface. This will isolate your problem a bit.

Russell Steen
Yes, I do have it. I can connect in SQL Server Management Studio Express using this specific user, but cannot expand the Databases tree node.
Marcos Buarque
Hum, sorry, now I can. I have changed some settings, trying to grant more rights to that user. I can log in SQL Server Management Studio Express, but still cannot log in from VS
Marcos Buarque
A: 

With Visual Studio, you're connecting through a "remote" connection, even though they're on the same machine. With Server Management Studio, you're connecting through a named pipe probably. You need to change the SQL configuration so that it allows remote connections. Here are instructions for how to do it.

Matthew Talbert
Thanks for the help. I have posted the solution I found above.
Marcos Buarque
A: 

You can test your SQL connection by connecting using LINQPad, Often find this solves problems with connections to new SQL Server instances at my workplace. http://www.linqpad.net/

DerX
A: 

Are you trying to specify the username and password to connect with in the connection string - ALA:

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

This actually uses SQL Authentication, not Integrated (Windows) authentication. What you might be looking for is this:

Data Source=myServerAddress;Initial Catalog=myDataBase;Trusted_Connection=True;

This would log into the database as the use running Visual Studio. Notice that the username/password aren't specified here - it uses the current Windows identity - in your case, that's the user running Visual Studio.

rwmnau
Just added a comment below my post: " Hi, I have found what the problem was. It was exactly this. My Visual Studio would pull automatically something like MACHINENAME\SQLEXPRESS. As it was pulled automatically, I did not bother taking a closer look at it. I finally realized the connection string that worked for me in my other application was .\SQLESXPRESS. When I entered it in Visual Studio, it did work. Thanks for the help anyway."
Marcos Buarque
+1  A: 

Hi, I have found the solution for this problem. My Visual Studio would pull automatically something like MACHINENAME\SQLEXPRESS. As it was pulled automatically, I did not bother taking a closer look at it. I finally realized the connection string that worked for me in my other application was .\SQLESXPRESS. When I entered it in Visual Studio, it did work. Thank you all for the help.

Marcos Buarque