Q:

Error when connecting to a SQL database: Cannot open database "Students.mdf" requested by the login. The login failed

I am really frustrated, this is very simple but didn't work with me. I'm trying to connect to my SQL Server which I don't need username and password when running SSMS. My server name is HP\SQLEXPRESS and I'm using the following connection string: 
string connectionString = "Data Source=HP\\SQLEXPRESS;Initial Catalog=Students.mdf;Integrated Security=SSPI;";

and I get the following error: 

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Cannot open database "Students.mdf" requested by the login. The login failed.
Login failed for user 'HP\Aymen'.

And when I specify the full address of my database as follows: 
string connectionString = "Data Source=HP\\SQLEXPRESS;Initial Catalog=c:\\Program Files\\Microsoft SQL Server\\MSSQL11.SQLEXPRESS\\MSSQL\\DATA\\Students.mdf;Integrated Security=SSPI;";

it also gives me the same error. 
Any suggestion? 

A:

I believe you have permissions problem for that user.
have you tried login with other user (admin user) to that db?

use your admin user to login to ssms.
under security, change the server Roles and user mapping to that specific user you want, and try to login again. do forget to give that user permission to "master".

A:

The problem solved. It seems that the problem is because I already have made a connection to the database using Entity Framework model. When I removed it and run the application again everything went fine. 

