0

I am trying to connect to SQL server through an asp.net page and I am getting this error: Cannot open database "dbname" requested by the login. The login failed. Login failed for user 'username'. And when I try to login directly at SQL using the same credentials it does connect successfully. And the username and password set in the webconfig are correct.

I tried setting a new password, remove the user from the database and add it again but it doesn't work through web only through SQL.

1
  • did you check the firewall and enable it from surface area configuration Commented Dec 14, 2011 at 10:19

1 Answer 1

1

The Database (or Initial Catalog) value in the connection string refers to a database (on the server) that doesn't exits or the login has no permissions.

When you connect using the SQL tools, it is picking up the default database (defined by the login) or you are sending a working value

Edit, after comment

The error says Cannot open database "dbname" requested by the login..

This means the database value in the asp.net generated connection string is wrong. Not much scope for ambiguity here

Sign up to request clarification or add additional context in comments.

3 Comments

The database does exist and the login has permissions as I can connect to the SQL Server through my local SQL Server by specifying the SQL IP and choose SQL Authentication and enter the login and password specified in the webconfig and I can open the database successfully
@Yasmine: it doesn't matter what you can do via SQL tools. What matters is the incorrect value asp.net is sending.
I figured it out, the values sent in asp.net where correct the problem was in the database name in SQL itself, you see the database was recently moved from another server and it seems that the db administrator who created the database on the new server has mistakenly added an extra character in it's name and I didn't notice it coz the name is supposed to be newxxx he named it newwxxx with double "w" :S Anyways thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.