MS SQL connectivity

Joakim Ziegler joakim at abargon.com
Thu Jun 6 12:48:44 EDT 2002


I'm currently faced with the... interesting task of talking to an MS SQL
Server 8.0 database running on W2k, from Python running on GNU/Linux. I've
looked at Dave Cole's MSSQL module, but I'm having problems getting it to
compile (using FreeTDS), it seems there are defines used in the C
extension module that are not defined in the freetds header files, such as
INT_CONTINUE and DBRPCRECOMPILE, and when I track the values of those
defines down on the web and fix that problem, the build continues a bit
further, but then fails with lots of undeclared functions, such as
dbcaltbind, dbclropt, DBCURCMD, DBCURROW, dbisopt, etc.

Additionally, according to the TODO file of that module,
Connection.commit() is unimplemented, which seems to hint that it's not
possible to use transactions.

Dave Cole hasn't answered my email, so I'm a bit at a loss for what to do
with that module (although it seems the simpler alternative).

The other alternative I've looked at is mxODBC with the FreeTDS ODBC
driver. This seems to be a more mature solution, but to be honest, I don't
know ODBC at all, and I'm having problems making it work. Does someone
know of a step-by-step guide to getting mxODBC with the FreeTDS ODBC
driver up and running on GNU/Linux, talking to an MS SQL Server? I've
defined the data source in /etc/odbc.ini, looking like this:

[ODBC Data Sources]
SUNTEST = Sunsystems test server

[SUNTEST]
Driver          = /usr/lib/libtdsodbc.so
Description     = Sunsystems test server
Trace           = No
Servername      = 192.168.1.39
Database        = SUNDB
UID             = <whatever>
PWD             = <whatever>

[Default]
Driver          = /usr/lib/libtdsodbc.so


(Yeah, I'm trying to talk to a SunSystems server. I know this is pretty
masochistic.) Anyway, I'm not at all sure about what these fields should
be, though, the database server is on the IP above, and the UID and PWD
are valid. Yet, when I try to do:

connection = mx.ODBC.iODBC.connect("DSN=SUNTEST")

I get:

LookupDSN: LoadDSN retured FALSETraceback (most recent call last):
[...]
mxODBC.InterfaceError: failed to retrieve error information(line 5939,
rc=-1)


I suspect there's some semi-easy way to make this work, as I said, I'm
totally unknowledgable when it comes to ODBC, I just want to get a
connection up to said database so I can do queries. :) Any hints,
recipes, HOWTOs, etc.?

-- 
--Joakim Ziegler



More information about the Python-list mailing list