连接到SQL Server的“意外的EOF”

时间:2013-01-16 20:38:17

标签: python sql-server pymssql

我正在尝试使用pymssql连接到在Windows Server 2008上运行的SQL Server 2012数据库。

db = pymssql.connect(host='xxx',user='xxx',password='xxx',database='xxx')

但是,我收到以下错误:

  

OperationalError:(20017,'DB-Lib错误消息20017,严重性9:\ n来自服务器的未发现的EOF \ nDB-Lib错误消息20002,严重性9:\ nAdaptive Server连接失败\ n')

完整错误是:

Traceback (most recent call last):
  File "XXX.py", line 2, in <module>
    conn = pymssql.connect(host = 'XXX.com', user = 'xxx', password = 'xxx', database = 'xxx')
  File "pymssql.pyx", line 556, in pymssql.connect (pymssql.c:7990)
    raise OperationalError(e[0])
OperationalError: (20017, '\xa0\xff\xaf\x02\x90_\x8d\x02L\xd6\xa7\x02\xda\xad;DB-Lib error message 20017, severity 9:\nUnexpected EOF from the server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed\n')

有人可以帮我弄清楚发生了什么吗?

2 个答案:

答案 0 :(得分:4)

我猜它可能是一个完全连接失败。我知道它说'EOF',但有时候这样的错误信息会产生误导。

我看看你是否可以ping the host首先从你运行脚本的地方开始。

其次,我会看看你是否可以在你正在使用的端口上获得tcp connection

当您使用https连接到http端口时,我听说过http连接上的EOF错误。我不确定这是否适用于此。

这出现在谷歌上。它可能有所帮助:

http://sourceforge.net/projects/pymssql/forums/forum/124111/topic/1672338

如果上述所有方法都有效,我会仔细检查用户名和密码是否正确;甚至可能会创建一个新用户。

最后,我要检查客户端库和服务器库版本是否兼容。

我希望这会有所帮助。

答案 1 :(得分:0)

pymssql需要freetds才能正常工作。在macOS上,在您首选的文本编辑器中打开/usr/local/etc/freetds.conf,然后更新以下配置:

[global]
# TDS protocol version
# tds version = auto
tds version = 7.0

您可以重试,看看错误是否消失。

参考here