【问题标题】:Connect to MSSQL Contained Database with python on Ubuntu?在 Ubuntu 上使用 python 连接到 MSSQL 包含的数据库?
【发布时间】:2015-02-05 03:52:06
【问题描述】:
我正在运行 Ubuntu 14.04.1 86_x64 服务器,我一直在尝试弄清楚如何连接到 MSSQL 2012 Contained Database。我一直在尝试使用 FreeTDS 驱动程序的 pymssql 2.1.0。根据 pymssql 网站,我确定问题出在 FreeTDS 驱动程序上。
我使用了tsql -H SERVER -p PORT -U USERNAME -P PASSWORD -D DATABASE,但出现错误:
来自服务器第 1 行的消息 18456(严重性 14,状态 1):
"Login failed for user 'USERNAME'."
错误 20002(严重性 9):
Adaptive Server connection failed
连接到服务器时出现问题
连接到不支持包含数据库的 MSSQL 2008 数据库时没有同样的问题。另外,我无法控制数据库上的设置。
【问题讨论】:
标签:
python-2.7
sql-server-2012
ubuntu-14.04
freetds
【解决方案1】:
发现 pymssql 2.1.1 将此作为其“与 Azure 的兼容性”的一部分进行了修复。
修复它的代码在 _mssql.pyx 的第 606-613 行,可以在 github 上找到。我把这些台词放在这里仅供参考。
# Put the DB name in the login LOGINREC because it helps with connections to Azure
if database:
if FREETDS_SUPPORTS_DBSETLDBNAME:
dbname_bytes = database.encode('ascii')
dbname_cstr = dbname_bytes
DBSETLDBNAME(login, dbname_cstr)
else:
log("_mssql.MSSQLConnection.__init__(): Warning: This version of FreeTDS doesn't support selecting the DB name when setting up the connection. This will keep connections to Azure from working.")