0

How should I create my SQL connection string in c# (esp. username and password), if I'm using windows authentication mode to connect to my SQL server. I tried using the system login credentials, but it's not working. When i try to open the connection, I'm getting "System.Data.SqlClient.SqlException" exception.

Please help..

5
  • Where is your connection string located? Is it a string in your program (not recommended), or in your app.config? Commented Jul 25, 2015 at 14:35
  • I'm using string in the program (whatever it is..), the exception says login failed for <username>. But if I goto server and check the database properties, my username is there in the "owner" field. Commented Jul 25, 2015 at 14:42
  • If you don't have it, add Trusted_Connection=True; to the end of your connection string and see if that works. Commented Jul 25, 2015 at 14:45
  • After adding Trusted_Connection=True; excetion is not raised, but my values are not going to the table. anyways thanks.. Commented Jul 25, 2015 at 15:22
  • 1
    Handy resource: connectionstrings.com Commented Jul 25, 2015 at 15:35

1 Answer 1

1

Which "data provider" are you using?

If it's System.Data.SqlClient then below connection string should work fine.

"Persist Security Info=False;Integrated Security=true;
    Initial Catalog=AdventureWorks;Server=MSSQL1"

Here is the link to MSDN article for more details. https://msdn.microsoft.com/en-us/library/ms254500(v=vs.110).aspx

For more accurate answer, please provide exception details.

By the way, if want to use "Windows authentication mode" then you needn't to provide user name and password. "Windows authentication mode" means you are using current users credentials. IMHO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.