错误 28000:用户 DOMAIN\\user with pyodbc 登录失败 [英] Error 28000: Login failed for user DOMAIN\\user with pyodbc
问题描述
我正在尝试使用 Python 通过使用 Window 身份验证连接到 SQL 数据库.我查看了此处的一些帖子(例如,此处),但建议的方法似乎不起作用.
I am trying to use Python to connect to a SQL database by using Window authentication. I looked at some of the posts here (e.g., here), but the suggested methods didn't seem to work.
例如,我使用了以下代码:
For example, I used the following code:
cnxn = pyodbc.connect(driver='{SQL Server Native Client 11.0}',
server='SERVERNAME',
database='DATABASENAME',
trusted_connection='yes')
但我收到以下错误:
Error: ('28000', "[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]
Login failed for user 'DOMAIN\\username'. (18456) (SQLDriverConnect); [28000] [Microsoft]
[SQL Server Native Client 11.0][SQL Server]Login failed for user 'DOMAIN\\username'.
(18456)")
(请注意,在上面的错误消息中,我分别用 DOMAIN
和 username
替换了实际域名和用户名.)
(Note that I replaced the actual domain name and user name with DOMAIN
and username
respectively, in the error message above.)
我也尝试使用我的 UID
和 PWD
,这导致了同样的错误.
I also tried using my UID
and PWD
, which led to the same error.
最后,我尝试按照上面链接中的建议更改服务帐户,但是在我的计算机上,当我转到 Properties
时没有 Log On
选项卡services.msc
的代码>.
Lastly, I tried to change the service account by following the suggestion from the link above, but on my computer, there was no Log On
tab when I went to the Properties
of services.msc
.
我想知道我做错了什么以及如何解决问题.
I wonder what I did wrong and how I can fix the problem.
推荐答案
从 Windows 机器连接:
对于 Microsoft 的 SQL Server ODBC 驱动程序,Trusted_connection=yes
告诉驱动程序使用Windows 身份验证";并且您的脚本将尝试使用运行脚本的用户的 Windows 凭据登录到 SQL Server.UID
和 PWD
不能用于在连接字符串中提供替代的 Windows 凭据,因此如果您需要以其他 Windows 用户的身份进行连接,则需要使用 Windows 的
With Microsoft's ODBC drivers for SQL Server, Trusted_connection=yes
tells the driver to use "Windows Authentication" and your script will attempt to log in to the SQL Server using the Windows credentials of the user running the script. UID
and PWD
cannot be used to supply alternative Windows credentials in the connection string, so if you need to connect as some other Windows user you will need to use Windows' RUNAS command to run the Python script as that other user..
如果您想使用SQL Server 身份验证"使用由 UID
和 PWD
指定的特定 SQL Server 登录,然后使用 Trusted_connection=no
.
If you want to use "SQL Server Authentication" with a specific SQL Server login specified by UID
and PWD
then use Trusted_connection=no
.
从非 Windows 计算机连接:
如果您需要从非 Windows 计算机连接并且 SQL Server 配置为仅使用Windows 身份验证"那么 Microsoft 的 SQL Server ODBC 驱动程序将要求您使用 Kerberos.或者,您可以使用 FreeTDS ODBC,在连接字符串中指定 UID
、PWD
和 DOMAIN
,前提是 SQL Server 实例配置为支持较旧的 NTLM 身份验证协议.
If you need to connect from a non-Windows machine and the SQL Server is configured to only use "Windows authentication" then Microsoft's ODBC drivers for SQL Server will require you to use Kerberos. Alternatively, you can use FreeTDS ODBC, specifying UID
, PWD
, and DOMAIN
in the connection string, provided that the SQL Server instance is configured to support the older NTLM authentication protocol.
这篇关于错误 28000:用户 DOMAIN\\user with pyodbc 登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!