简体   繁体   English

为什么ADO.NET仍然使用错误的用户连接到SQL Server?

[英]Why ADO.NET still connected to SQL Server with wrong user?

I am running Microsoft SQL Server 2014. I try to connect to SQL Server using ADO.NET in a C# application. 我正在运行Microsoft SQL Server2014。我尝试在C#应用程序中使用ADO.NET连接到SQL Server。 My connection string is: 我的连接字符串是:

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

My Initial Catalog is a right and existed database. 我的初始目录是一个正确的现有数据库。 But my username is a wrong username! 但是我的用户名是错误的用户名! The Password I have inserted is also wrong already. 我插入的密码也已经错误。 But ADO.NET still connected to my database and I can execute query and do everything with my database. 但是ADO.NET仍然连接到我的数据库,我可以执行查询并使用我的数据库进行所有操作。 How can I fix it? 我该如何解决?

You have provided both Integrated Security=SSPI; 您同时提供了Integrated Security=SSPI; as well as username & password so it by default takes integrated Security ie windows authentication and thus you are able to connect with wrong credentials as well. 以及用户名和密码,因此默认情况下它将采用integrated Security即Windows身份验证,因此您也可以使用错误的凭据进行连接。

So, either user Integrated Security or your credentials as you do when connecting to SSMS, when it asks for either Windows authentication or SQL Server authentication 因此,当用户要求Windows authenticationSQL Server authentication时,无论是用户Integrated Security还是您连接到SSMS时的凭据

From MSDN :- MSDN :-

Integrated Security When false, User ID and Password are specified in the connection. 集成安全性如果为false,则在连接中指定用户ID和密码。 When true, the current Windows account credentials are used for authentication. 设置为true时,将使用当前Windows帐户凭据进行身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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