SQL Server 2008 错误 18456 状态 58,用户“登录失败”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14862217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:41:32  来源:igfitidea点击:

SQL Server 2008 error 18456 state 58, Login failed for user "

sqlsql-server-2008login

提问by Karl Arsenault

I have a Visual Studio C++ project (unmanaged C++) in which I try to connect to a SQL Server 2008 instance on another machine in the LAN. I use TCP/IP. My connection string is:

我有一个 Visual Studio C++ 项目(非托管 C++),我尝试在其中连接到 LAN 中另一台机器上的 SQL Server 2008 实例。我使用 TCP/IP。我的连接字符串是:

"DRIVER={SQL Server Native Client 10.0};Server=tcp:169.254.204.232,1433;Network Library=DBMSSOCN;Initial Catalog=myDB;User ID=myDBUser;Password=myPassword;"

Important fact:I am able to successfully connect remotely to that instance with user id myDBUser and password myPassword using SSMS -- using SQL Authentication mode (and specifying TCP/IP in the connection options)! Also, once logged in I can successfully navigate the database myDB.

重要事实:我能够使用 SSMS 使用用户 ID myDBUser 和密码 myPassword 成功远程连接到该实例——使用 SQL 身份验证模式(并在连接选项中指定 TCP/IP)!此外,一旦登录,我就可以成功导航数据库 myDB。

So yes, I have enabled Mixed mode authentication on my server.

所以是的,我在我的服务器上启用了混合模式身份验证。

Also note that the same code was successfully connecting when my instance was local and I was using Windows Authentication. In other words, what changed since this whole thing last worked is that I moved my server to another machine, am now using SQL Authentication, and therefore changed my connection string -- the code has otherwise not changed at all.

另请注意,当我的实例在本地并且使用 Windows 身份验证时,相同的代码已成功连接。换句话说,自从整个事情最后一次工作以来发生的变化是我将我的服务器移到另一台机器上,现在使用 SQL 身份验证,因此更改了我的连接字符串——否则代码根本没有改变。

Here is the error message I get in my SQL Server 2008 instance's Server Logs:

这是我在 SQL Server 2008 实例的服务器日志中收到的错误消息:

Login failed for user ". Reason: An attempt to login using SQL Authentication failed. Server is configured for Windows Authentication only. Error: 18456, Severity: 14, State: 58.

用户“登录失败。原因:尝试使用 SQL 身份验证登录失败。服务器仅配置为 Windows 身份验证。错误:18456,严重性:14,状态:58。

Notice that the user being quoted in that error message is blank, even though in my connection string I specify a non-blank user ID.

请注意,该错误消息中引用的用户为空,即使在我的连接字符串中我指定了一个非空的用户 ID。

Other connection strings I tried that give the same result:

我尝试过的其他连接字符串给出了相同的结果:

"DRIVER={SQL Server Native Client 10.0};Server=MACHINE2;Database=myDB;User ID=myDBUser;Password=myPassword;" (where MACHINE2 is the windows name of the machine hosting the sql server instance.)

I do not specify an instance name in the above connection string because my instance is installed as the default instance, not a named instance.

我没有在上面的连接字符串中指定实例名称,因为我的实例是作为默认实例安装的,而不是命名实例。

Any ideas on how to solve this?

关于如何解决这个问题的任何想法?

UPDATE: I solved this problem it seems. Are you ready to find out how silly and totally unrelated that error message was? In the connection string, I just changed "User ID" to "uid" and "Password" to "pwd", and now it works. I now see "Connected successfully" in my SQL Server logs...

更新:我似乎解决了这个问题。您准备好找出该错误消息是多么愚蠢和完全无关了吗?在连接字符串中,我只是将“用户 ID”更改为“uid”,将“密码”更改为“pwd”,现在它可以工作了。我现在在 SQL Server 日志中看到“连接成功”...

采纳答案by Karl Arsenault

The answer: In the connection string, I just changed "User ID" to "uid" and "Password" to "pwd", and now it works. I now see "Connected successfully" in my SQL Server logs...

答案:在连接字符串中,我只是将“用户 ID”更改为“uid”,将“密码”更改为“pwd”,现在它可以工作了。我现在在 SQL Server 日志中看到“连接成功”...

回答by David Aleu

Try running SELECT SERVERPROPERTY('IsIntegratedSecurityOnly');if it returns 1 is Windows Authentication if 0 Mixed. If it returns 1 is definitely Windows Authentication and there must be something else wrong.

SELECT SERVERPROPERTY('IsIntegratedSecurityOnly');如果返回 1 则尝试运行,如果 0 混合则为 Windows 身份验证。如果它返回 1 肯定是 Windows 身份验证,并且肯定有其他错误。

回答by Adarsh

I think I solved this problem by doing this...

我想我通过这样做解决了这个问题......

right click on servername on object explorer -> Properties -> Security -> Changed server authentication to SQL server and Windows authentication mode -> click OK.

右键单击对象资源管理器上的服务器名称 -> 属性 -> 安全性 -> 将服务器身份验证更改为 SQL 服务器和 Windows 身份验证模式 -> 单击确定。

after that open server on object explorer -> Expand security -> Expand Login -> right click on your login -> properties -> type new password -> confirm password -> OK.

在对象资源管理器上打开服务器 -> 展开安全 -> 展开登录 -> 右键单击​​您的登录名 ->​​ 属性 -> 输入新密码 -> 确认密码 -> 确定。

then disconnect your SQL and restart your system. then login SQL server 2008 with changed password in sql authentication mode.

然后断开您的 SQL 并重新启动您的系统。然后在sql身份验证模式下使用更改的密码登录SQL Server 2008。

Thanks :)

谢谢 :)