使用pyodbc从Linux到Windows SQL Server进行身份验证 [英] Authenticate from Linux to Windows SQL Server with pyodbc
问题描述
我正在尝试使用pyodbc从Linux计算机连接到Windows SQL Server.
I am trying to connect from a linux machine to a windows SQL Server with pyodbc.
我确实有两个限制:
- 需要使用Windows域帐户登录
- 需要使用python3
- 需要从Linux到Windows
- 需要连接到特定实例
我按照Microsoft的说明设置了环境并使其正常运行(我可以导入pyodbc并使用已配置的贻贝驱动程序).
I set up the environment as described by microsoft and have it working (I can import pyodbc and use the configured mussel driver).
我不熟悉Windows域身份验证,而我不熟悉Windows域身份验证,所以这里就是我的问题所在.
I am not familiar with Windows domain authentication and what not, so there is where my problem is.
我的连接字符串:
DRIVER={ODBC Driver 17 for SQL Server};SERVER=myserver.mydomain.com;PORT=1433;DATABASE=MyDatabase;Domain=MyCompanyDomain;Instance=MyInstance;UID=myDomainUser;PWD=XXXXXXXX;Trusted_Connection=yes;Integrated_Security=SSPI
应该使用"Trusted_Connection"来使用Windows域身份验证,而不是直接通过SQL Server进行身份验证.
Supposedly one should use "Trusted_Connection" to use the Windows domain authentication instead of directly authenticating with the SQL server.
运行 pyodbc.connect(connString) 时出现的错误:
The error I get when running pyodbc.connect(connString):
pyodbc.Error: ('HY000', '[HY000] [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No Kerberos credentials available (851968) (SQLDriverConnect)')
我从其他来源了解到,该代码应在Windows上运行,因为此代码将使用当前登录用户的凭据.
From other sources I read this should work on Windows as this code would use the credentials of the currently logged in user.
我的问题是如何使用Windows域凭据从Linux连接到Windows SQL Server实例.
My question is how can I connect to a Windows SQL Server instance from Linux using Windows Domain credentials.
推荐答案
我最终使用了pymssql库,该库基本上是FreeTDS驱动程序之上的pyodbc.它开箱即用.
I ended up using the pymssql library which basically is pyodbc on top of the FreeTDS driver. It worked out of the box.
奇怪的是,我很难找到这个库.
Weird how I had such a hard time discovering this library..
这篇关于使用pyodbc从Linux到Windows SQL Server进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!