【问题标题】:Why ADO.NET still connected to SQL Server with wrong user?为什么 ADO.NET 仍然使用错误的用户连接到 SQL Server?
【发布时间】:2015-05-05 01:51:37
【问题描述】:

我正在运行 Microsoft SQL Server 2014。 我尝试在 C# 应用程序中使用 ADO.NET 连接到 SQL Server。 我的连接字符串是:

var myConnection = new SqlConnection("Data
 Source=VIRTUAL-ADMIN\\SQLEXPRESS;" +
                 "Integrated Security=SSPI;" +
                 "Initial Catalog=StudentManagement;"+
                 "User id=...;"+
                "Password=...");

我的初始目录是一个正确且存在的数据库。 但是我的用户名是错误的用户名! 我输入的密码也已经错了。 但是 ADO.NET 仍然连接到我的数据库,我可以执行查询并使用我的数据库做所有事情。 我该如何解决?

【问题讨论】:

  • 您好,您可以尝试对它进行 sql 配置并查看它是否使用同一用户连接吗?
  • 谢谢,我的问题已经解决了

标签: c# asp.net sql-server ado.net


【解决方案1】:

您同时提供了Integrated Security=SSPI; 以及用户名和密码,因此默认情况下它采用integrated Security 即Windows 身份验证,因此您也可以使用错误的凭据进行连接。

因此,用户 Integrated Security 或您的凭据,就像连接到 SSMS 时一样,当它要求 Windows authenticationSQL Server authentication

来自MSDN:-

Integrated Security 当为 false 时,用户 ID 和密码在 连接。如果为 true,则当前的 Windows 帐户凭据为 用于身份验证。

【讨论】:

  • 当 Integrated Security false 时,在连接中指定用户 ID 和密码。如果为 true,则使用当前的 Windows 帐户凭据进行身份验证。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-15
  • 2014-01-02
  • 1970-01-01
  • 2011-06-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多