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!

Ropstah
  • 205
  • 5
  • 11
  • 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: http://stackoverflow.com/questions/7114164/cannot-open-database-test-requested-by-the-login-the-login-failed http://stackoverflow.com/questions/7119602/how-to-make-sql-server-find-a-login-matching-the-name-provided http://stackoverflow.com/questions/7130644/how-to-connect-to-sql-server-express-database http://stackoverflow.com/questions/7132639/how-to-create-new-database-in-sql-server-express-2008-and-allow-for-connecting – Aaron Bertrand Aug 20 '11 at 16:54

1 Answers1

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.

Peter Schofield
  • 1,639
  • 9
  • 11
  • 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