SQL Server – Login Failed for User ‘web_user’ on Database ‘user_auth.mdf’

sql server

I am trying to deploy my first VB.NET application on GODADDY. I created a SQL server database and was able to create tables using SQL Server Management Studio. I created a user web_user and was able to login to the GODADDY database using that user. However when my website tries to connect with this database using the same user id and password, I get the following error:

Cannot open database "user_auth.mdf" requested by the login. The login failed. Login failed for user 'web_user'.

My connection string is mentioned below. It is similar to what was recommended by GODADDY:

<add name="ConnectionString" 
     connectionString="Server=XYZ;Database=user_auth.mdf;User ID=web_user;Password=zzz;
     Trusted_Connection=False" providerName="System.Data.SqlClient" />

Please help. Its driving me nuts. Stack Trace is:

[SqlException (0x80131904): Cannot open database "user_auth.mdf" requested by the login. The login failed.

Login failed for user 'web_user'.]

Best Answer

If you created the database using SSMS, you should use the logical database name and not the file with the .mdf extension in your connection string.

Use

Server=XYZ;Database=user_auth;User ID=web_user;Password=web_user 

for your connection string and let SQL Server worry about the file-related details.