Connecting to SQL Server from UNIX

Benji York benji at benjiyork.com
Sun Oct 24 03:22:31 CEST 2004


yuba at conwaycorp.net wrote:
> Is it possible for me to connect to a MS SQL-Server from a UNIX box via Python
> (2.3)? 

Check out ODBTP (http://odbtp.sourceforge.net/) and my (alpha) Python DB 
API 2.0 bindings for it (http://benjiyork.com/odbtp.html).

You install the ODBTP service on a Windows machine (the one with SQL 
Server or a different one) and use the ODBTP client to connect to it 
from Unix, Linux, Windows, etcetera.

Here's a small example program:


import odbtpapi

connectString = 'Driver=SQL Server;Server=10.0.0.1;UID=sa;PWD=thepassword;'
connection = odbtpapi.connection(connectString, server='10.0.0.2')
cursor = connection.cursor()
sql = 'select * from MyDatabase..MyTable where someColumn = ?'
cursor.execute(sql, ['A Value'])
for row in cursor.fetchall():
     print row

print cursor.description

-- 
Benji York
benji at benjiyork.com




More information about the Python-list mailing list