Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to connect to my SQL Server express instance from my ASP.NET web application but it doesn't work. The generic error message given to the application is:

Cannot open database 'xxx' requested by the login. The login failed. Login failed for user 'xxx'.

I can connect using those credentials from Management Studio Express and see the tables and data, but the connection through my web application just fails. I'm using the following connection string:

Data Source=(local)\sqlexpress;User Id=xxx;Password=xxx;Initial Catalog=xxx;

SQL Server Express is allowed to use remote connections and I have named pipes and TCP/IP enabled.

Any help would be greatly appreciated!

share|improve this question
This is your 5th question about this same problem (4 are on stackoverflow under the name Ropstah). Can you please verify that SELECT @@SERVERNAME in Management Studio matches your connection string. My guess is that you have multiple instances of SQL Express, and/or a manual instance and one set up with Visual Studio, or you're using user instances... – Aaron Bertrand Aug 20 '11 at 16:51
For background and countless other questions that have been asked repeatedly by this same person (mostly to save time for other responders) please see these SO questions:………… – Aaron Bertrand Aug 20 '11 at 16:54
up vote 2 down vote accepted

Have you tried changing the (local) in the datasource to the actual servername? When you use Management Studio, and connect to this SQL Server - is it the same datasource as in the connection string?

In Management Studio, have you checked the SQL Server logs in the Management section? If the connection is getting to SQL Server, but being refused, it will write an entry in here. It will also give an error code (eg 18456), and a state number possibly - you should be able to look this up online.

share|improve this answer
The servername (local) is correct and works. The error log states: Login failed for user 'xxx'. REason: Failed to open the explicitly specified database. [ClIENT:]. Error 18456, Severity: 14, State: 38 – Ropstah Aug 20 '11 at 14:05
Ok, when you check the login in Management Studio, it will have a default database defined - is this database specified the one you are trying to open? – Peter Schofield Aug 20 '11 at 14:08
Yes it is. And the connection string used in my web application also states: Initial Catalog=databasename; – Ropstah Aug 20 '11 at 14:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.