configuring ODBC DSN with a python script

Andy Robinson andy at reportlab.com
Thu Feb 5 02:22:16 CET 2004


On 4 Feb 2004 11:09:52 -0800, jani at persian.com (Jani Yusef) wrote:

>I am building an application which, unfortunately, *must* use an
>access db. The users will have the relevane mdb file installed on
>their system. As part of the installer. Now, the part I am stuck on is
>how do I configure the ODBC dsn without having the user open up the
>ODBC control panel which will in all honestly just scare and confuse
>them. ;)
>Has anyone approached this problem before? What did you do?
>Thanks!!

Most drivers let you pass this in at runtime by building a string with
a number of key/value parameters.  With Access, the magic one
is Dbq which refers to the file name.  This works for me....

>>> import mx.ODBC.Windows
>>> dc = mx.ODBC.Windows.DriverConnect
>>> conn = dc("Driver={Microsoft Access Driver
(*.mdb)};Dbq=c:\\mydir\\myfile.mdb;Uid=Admin;Pwd=
;")
>>> cur = conn.cursor()
>>> cur.execute('select count(*) from Codes')
>>> cur.fetchall()
[(1144,)]
>>>


- Andy Robinson

p.s. Steve Holden tipped me of



More information about the Python-list mailing list