Python Pyodbc使用SQL Server身份验证连接到Sql Server [英] Python pyodbc connect to Sql Server using SQL Server Authentication

查看:429
本文介绍了Python Pyodbc使用SQL Server身份验证连接到Sql Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

窗口用户的详细信息与我登录的Sql Server用户不同.因此,我尝试使用pyodbc通过用户名(Admin_JJack)和密码连接到数据库.但是对于Window User(Jack),连接显示失败,并且我不知道哪里出了问题.

The window user details is different from the Sql Server user I log in. So I had tried to use pyodbc connect to the database using the username(Admin_JJack) and password. But the connection show fails for the Window User(Jack) and I don't know where goes wrong.

我的连接字符串:

connection = pyodbc.connect(
    "Driver={"SQL Driver"};"
    "Server= "ServerName";"
    "Database="DatabaseName";"
    "UID="UserName";"
    "PWD="Password";"
    "Trusted_Connection=yes"
)

pyodbc.InterfaceError :("28000","[28000] [Microsoft] [SQL Server Native Client 11.0] [SQL Server]用户'Jack'的登录失败.(18456)(SQLDriverConnect);

pyodbc.InterfaceError: ('28000', "[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'Jack'. (18456) (SQLDriverConnect);

如何使用sql server身份验证连接到数据库?

How to connect to the database using sql server authentication ?

推荐答案

使用"Trusted_Connection = yes"时,UID和PWD密钥都将被忽略,并且Windows帐户用于身份验证.

When you use "Trusted_Connection=yes" both the UID and PWD keys are ignored and the Windows account is used for authentication.

如果要使用UID和PWD值而不是Windows NTLM帐户进行身份验证,则必须使用"Trusted_Connection = No"或从连接字符串中删除此选项.

If you want to use the UID and PWD values for authentication instead of the Windows NTLM account you must use "Trusted_Connection=No" or remove this option from the connection string.

受信任的连接

指定用户是否通过使用来通过用户帐户建立连接 Kerberos [RFC4120]或其他特定于平台的身份验证 由fIntSecurity字段指定(有关详细信息,请参见[MS-TDS] 第2.2.6.4节).

Specifies whether a user connects through a user account by using either Kerberos [RFC4120] or another platform-specific authentication as specified by the fIntSecurity field (for details, see [MS-TDS] section 2.2.6.4).

有效值为是","1"或空字符串,它们是 等价或否".如果未指定值否",则该值 使用是".

The valid values are "Yes", "1", or empty string, which are equivalent, or "No". If the value "No" is not specified, the value "Yes" is used.

如果该值为"No",则必须使用UID和PWD密钥 与数据源建立连接.

If the value is "No", the UID and PWD keys have to be used to establish a connection with the data source.

如果连接中未包含DSN密钥和UID密钥 字符串,或者如果UID密钥的值为空字符串,则为 Trusted_Connection密钥必须为是".如果Trusted_Connection 连接字符串中未指定密钥,该值必须为 从DSN密钥中的设置内容获得.如果 DSN中未指定Trusted_Connection密钥,或者给定的DSN未指定Trusted_Connection密钥 不存在,默认值为否".

If the DSN key and the UID key are not included in the connection string or if the value of the UID key is an empty string, the value of the Trusted_Connection key has to be "Yes". If the Trusted_Connection key is not specified in the connection string, the value has to be obtained from the contents of the settings in the DSN key. If the Trusted_Connection key is not specified in DSN or if the given DSN does not exist, the default value is "No".

如果Trusted_Connection密钥的值为是",则UID和 PWD密钥将被忽略.否则,必须指定UID密钥.

If the value of the Trusted_Connection key is "Yes", both the UID and PWD keys are ignored. Otherwise, the UID key has to be specified.

在Microsoft实施中,此用户帐户是Windows用户 帐户和NTLM身份验证[MSDN-NTLM]的值是 Trusted_Connection密钥为是".

In Microsoft implementations, this user account is a Windows user account and NTLM authentication [MSDN-NTLM] is used when the value of the Trusted_Connection key is "Yes".

源: https://msdn .microsoft.com/

这篇关于Python Pyodbc使用SQL Server身份验证连接到Sql Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆