0

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!

2

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.

  • 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: xxx.xxx.xxx.xxx]. 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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