用于支持windows身份验证的pymssql模块。现在看来并非如此。虽然在一些地方,它仍然表明它应该工作。我一直未能找到这个问题的确切答案,也无法找到解决办法。最相关的联系:
https://groups.google.com/forum/#!topic/pymssql/QDMLTGBNeU0
Pymssql1.0支持它,因为它使用并依赖MS提供的DLL,而DLL是Server客户端堆栈的一部分。这个堆栈负责处理所有NTLM谈判等等。这意味着,除其他外,它是一个Windows专用的解决方案。
我可以模拟各种网络环境,所以我尝试了许多不同的设置。我试图使用此脚本使用windows身份验证连接到远程MSSQL服务器。这就是问题所在。
根据我的研究,包括上面的链接,有两种方法可以通过pymssql模块使用windows身份验证来工作。
第一个方法:使用当前用户凭据的:
pymssql.connect(server='server')
# credentials come from active windows session
# some research shows that a "trusted=True" keyword should be provided.第二种方法:使用给定用户凭据的:
pymssql.connect(server='server', user=r'domain\user', password='pass')
# credentials are given in code and somehow converted to a
# windows authentication in the background
# some research shows that a "trusted=True" keyword should be provided._mssql模块的使用也是如此。
备注:
关于这一专题的其他问题:
pymssql: How to use windows authentication when running on a non-windows box
Unable to connect using pymssql with windows authentication
https://stackoverflow.com/questions/27692366/mssql-python-windows-authentication
发布于 2015-09-21 11:49:58
发布于 2015-12-17 21:04:43
我能够使用python 2.7.11 64位、pymssql 2.1.1 win 64、windows 10、sqlserver 2012以及windows身份验证来解决这个问题:
conn = pymssql.connect(server = 'EDDESKTOP', database = 'baseballData')并在MSSQLSERVER配置管理器>MSSQLSERVER网络配置->协议中为MSSQLSERVER->启用tcp/ip启用TCP/IP连接。
发布于 2015-03-30 15:44:45
我最近也遇到了同样的挑战。我最初还使用了Python2.7和windows身份验证。我能够连接的唯一方法是使用IronPython并导入clr模块。我不知道它为什么会起作用,我希望有人能给我解释一下这个问题。不同之处在于我的服务器是本地的,里面的数据库是用‘实体框架-代码优先’形成的。下面是最后将我连接到服务器的代码。
import clr
clr.AddReference('System.Data')
from System.Data.SqlClient import *
Conn_string = 'data source=Server_Name; initial catalog=Database_Name; trusted_connection=True'
ScheduleConn = SqlConnection(Conn_string)
ScheduleConn.Open()如果这不能解决你的问题,我希望它能让你更接近你的解决方案。
https://stackoverflow.com/questions/29349607
复制相似问题