简体   繁体   中英

My connection string using Windows authentication for SQL Server doesn't work

I'm having problems whenever I run my application, it says that the connection is wrong. The error is User '' has failed.

I think I didn't specify the user id and password but I don't know what is the user id and my password.

Here's my connection string

public SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=PayrollDB;Persist Security Info=True;");

Thanks in advance!

public SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=PayrollDB;Persist Security Info=True;Integrated Security=true;");

将Intergrated Security = true添加到连接字符串。

You need to add the connection string attribute: Integrated Security = true . And this will work correctly.

要允许Windows身份验证,您需要在连接字符串中以tru的形式添加集成安全性集,如下所示:

public SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=PayrollDB;Persist Security Info=True;Intergrated Security=true;");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM