Python to MS SQL Server

Paul Brian paul1brian at yahoo.com
Wed Jun 19 08:03:02 EDT 2002


Richard,

I can thoroughly recommend mx.ODBC from egenix.com
It is a robust package at a reasonable price, and just works. You also get
mx.datetime which is v good as well.
I think it is a 30 day evaluation.

Below is code snippet on connecting to an sql server, assuming you have ODBC
drivers loaded up on your (windows) machine already. (the server address
could be DNS, or netbios, depending on how you connect now. does not really
matter, but is nice to be consistent)
#note the string os on continuos string, formatting a bit off here.

---------------------
#ODBC connection string - see msdn for more details, but this covers most
eventualities
testdsn = r''driver={SQL Server};
server=mySQLServer;uid=webserver;pwd=webserver;database=dbtest;app=Example"

db = mx.ODBC.Windows.DriverConnect(testdsn)

c = db.cursor()
c.execute('select * from tblTest')
z = c.fetchall()

pprint.pprint(z)

c.close()
db.close()

del(c)
del(db)
---------------------------


"Richard Kessler" <richardkessler at matteicos.com> wrote in message
news:3D0F8099.8080106 at matteicos.com...
> I am interested in using Python in a MS SQL Server environment, but do
> not see any database modules out there, especially for native versus
> using ODBC. Is there such a module?
>
> Thanks in advance.
>
> - Richard
>





More information about the Python-list mailing list