-2

When trying to establish a connection I get the exception below:

System.Data.SqlClient.SqlException occurred
  HResult=0x80131904
  Message=Login failed for user ''.
  Source=.Net SqlClient Data Provider
  StackTrace:
<Cannot evaluate the exception stack trace>

I keep getting the above error, here is my code:

SqlConnection conn = 
  new SqlConnection(@"Data Source = Computer-DELL\SQLEXPRESS;Initial Catalog = Drivers");

conn.open();
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Armee
  • 11
  • 5

2 Answers2

2

Your connection string does not have Username and Password and or Integrated Security.

With Integrated Security:

Data Source=localhost\SQLSERVER;Initial Catalog=YourDataBaseName;Integrated Security=True;

With username and password:

Data Source=localhost\SQLSERVER;Initial Catalog=YourDataBaseName;persist security info=True;user id=someusername;password=somepassword;
sharp
  • 1,191
  • 14
  • 39
0

Assuming they have permission, local user:

SqlConnection conn = new SqlConnection(@"Data Source = Computer-DELL\SQLEXPRESS;Initial Catalog = Drivers;Trusted_Connection=True;")
conn.open();
SCramphorn
  • 447
  • 4
  • 23