0
SqlConnection con = new SqlConnection("Data Source=DESKTOP-OCSSDNA; Initial Catalog=Login; Connect Timeout = 00;");
con.Open();

Hi, this code is connection string my login form; but error message: Login failed for user ''. help please. My sql have not user id and user password.

  • You can set Integrated Security=True in your connection string. Like this: `Data Source=DESKTOP-OCSSDNA; Initial Catalog=Login; Connect Timeout = 00; Integrated Security=True;` When that is set to true, the current Windows account credentials are used for authentication. – Rigerta Sep 11 '17 at 12:51
  • if set Integrated Security=True after error message:Cannot open database "Login" requested by the login. The login failed. –  Sep 11 '17 at 13:02
  • Your user might not have rights to that database. Can you login locally? If so, could it be that you have a named instance, not the default SQL Server instance? – Rigerta Sep 11 '17 at 13:04
  • Server name: DESKTOP-OCSSDNA \ TEST and windows authentication database name: Login table name: Registered Do not you need to get in? –  Sep 11 '17 at 13:08
  • You also need to write the Data Source complete, with the instance name included. So your final connection string would be like this: `Data Source=DESKTOP-OCSSDNA\TEST; Initial Catalog=Login; Connect Timeout = 00; Integrated Security=True;` – Rigerta Sep 11 '17 at 13:10
  • DESKTOP-OCSSDNA\TEST; error: unrecognized escape sequence –  Sep 11 '17 at 13:12

2 Answers2

0

According to the comments, you have a named instance. The last issue you have is coming up because you need to escape the '\':

Try the following, should work:

Data Source=DESKTOP-OCSSDNA\\TEST; Initial Catalog=Login; Connect Timeout = 00; Integrated Security=True;

For more information you could check this article.

Rigerta
  • 3,959
  • 15
  • 26
0

Try this it will work:

SqlConnection con = new SqlConnection("Data Source=DESKTOP-OCSSDNA; Initial Catalog=Login; Integrated Security=True";)
con.Open();