System.Data.SqlClient.SqlException(0x80131904):用户登录失败

时间:2016-04-02 11:43:18

标签: sql-server sql-server-2012 connection-string

这个问题可能已经提出,但我是第一次这样做,而且我不知道我错在哪里。 我想将我的asp.net网页连接到SQL Server 2012.我的连接字符串是:

static private SqlConnection connection = new SqlConnection(@"Data Source=DESKTOP-U8B6J4S\SQLEXPRESS; Initial Catalog=DBSera; User ID=DESKTOP-U8B6J4S\PROGRAMARE; Password=");

当我连接SQL时:

enter image description here

enter image description here

我得到的错误是:

  

System.Data.SqlClient.SqlException(0x80131904):用户登录失败' DESKTOP-U8B6J4S \ PROGRAMARE'。

所以我做错了,我应该怎么做才能建立连接?提前谢谢!

1 个答案:

答案 0 :(得分:2)

如果要对SQL Server使用Windows身份验证,请不要在连接字符串中指定用户ID和密码。完全取出这两个参数。 通过添加这些参数,SQL Server认为您希望使用SQL身份验证。

使用此连接字符串:

"Data Source=DESKTOP-U8B6J4S\SQLEXPRESS; Initial Catalog=DBSera; Integrated Security=True;"