-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();
2
  • 1
    What about entering a user ID and password, or trusted connection? Commented Jul 4, 2017 at 11:05
  • 1
    Duplicate that will do: stackoverflow.com/q/14567939/993547 Commented Jul 4, 2017 at 11:06

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

If it is local and they have rights use the integrated security if its easier.
0

Assuming they have permission, local user:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.