08.28.08
pymssql - connecting to sql server using python on *NIX
I recently wrote some python scripts that pull information from a SQL Server 2005 database. The scripts are hosted on a redhat machine, so I installed freetds and pymssql to help wire things up. I then started python and typed:
>import _mssql
>mssql=_mssql.connect('123.123.123.123:1433', 'user', 'pass')
which gave me this rather cryptic error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_mssql.error: DB-Lib error message 20017, severity 9:
Unexpected EOF from the server
Net-Lib error during Operation now in progress
Error 115 - Operation now in progressDB-Lib error message 20002, severity 9:
Adaptive Server connection failed
It turns out the problem is related to the TDS protocol version: for SQL Server 2005 it should be 8.0. To set this up, edit /usr/local/etc/freetds.conf and change it. The entry for my SQL Server machine looks like
[mssqlhost]
host = 123.123.123.123
port = 1433
tds version = 8.0
encryption = request
Once I made that change everything worked. Huzzah!