[英]Fix "login failed for user.." error in connecting Microsoft SQL server in Python
I am receiving a very common error while trying to connect Microsoft SQL Server using pyodbc
.我在尝试使用
pyodbc
连接 Microsoft SQL Server 时收到一个非常常见的错误。 I've tried the solutions suggested here before, but none of them solved my problem.我之前尝试过这里建议的解决方案,但没有一个能解决我的问题。
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server= server_name;'
'Database= database_name;'
'UID= user_id;'
'PWD= password;')
InterfaceError: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]
Login failed for user ' '. (18456) (SQLDriverConnect); [28000] [Microsoft][ODBC SQL Server Driver]
[SQL Server]Login failed for user ' '. (18456)")
When I connect the database via Microsoft SQL Server Management Studio 18
app, below is how I connect.当我通过
Microsoft SQL Server Management Studio 18
应用程序连接数据库时,以下是我的连接方式。 I copy and paste server name, login, and password information to my Python code as shown above.我将服务器名称、登录名和密码信息复制并粘贴到我的 Python 代码中,如上所示。 My OS is Windows 10. When I call
select @@version
, I get Microsoft SQL Server 2014 (SP3-GDR) (KB4583463)...
我的操作系统是 Windows 10。当我调用
select @@version
时,我得到Microsoft SQL Server 2014 (SP3-GDR) (KB4583463)...
Admittedly my python skills are not the best but I'm suspicious of all the single quotes in your connection string.诚然,我的 python 技能不是最好的,但我怀疑你的连接字符串中的所有单引号。
In the error message Login failed for user ' '
is that blank value for the use what you actually see or have you stripped that out?在错误消息
Login failed for user ' '
中,使用的空白值是您实际看到的还是您已将其删除? If that's what you actually see then I think your connection string is malformed.如果这是您实际看到的,那么我认为您的连接字符串格式不正确。
Refer to the sample here for how to build out a connection string.有关如何构建连接字符串的信息,请参阅此处的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.