Aymen Kareem Aymen Kareem - 1 month ago 16
SQL Question

SQL Connection String User Id and Password

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?

Answer

The problem solved. It seems that the problem is because I made Entity Framework model before. When I removed it and run the application again everything went fine.

However, if I want to create an application using database connection, which connection is preferred? SQL statement or Entity Framework?

Comments