[Tutor] connecting to odbc

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Thu May 8 05:12:01 2003


On Thu, 8 May 2003, ali wrote:

> i have a problem connecting to my ms access database using odbc???

Hi Ali,

Hmmm... your question is a little specialized; you may want to try asking
on the python-win32 mailing list, as this is less about getting Python
working and more with getting the ODBC driver working.  *grin*

Python-win32 can be found here:

    http://mail.python.org/mailman/listinfo/python-win32


> according to the documentation i should connect using this proforma:

Can you point us toward the documentation that you're looking at?  We need
to focus our search, because there are a few ODBC drivers out there.
Until we know more, we have no choice but to guess which one you're using.


Since you mentioned MS Access, I tried finding documentation on ODBC from
here:

    http://www.python.org/windows/win32/odbc.html

It shows how to create an ODBC connection, and it looks very much like
what you're doing now.


> how do you create a "connection string"???
>
> i tried the "old" way of doing it and it worked...
> ###########################
> import odbc as o
> con = o.odbc("mydsn/uid/pwd")
> ###########################

This is the way that the link above describes, and if it works, I don't
see anything wrong about that.  *grin*



> but i dont know how to connect using the "new" way???
> ###########################
> import odbc as o
> con = o.odbc("dsn=..........") # <-- here is where my problem is
> ###########################

If you're referring to the documentation for mxODBC,

    http://www.lemburg.com/files/python/mxODBC.html

then I don't think it applies!  The 'odbc' module that comes standard with
PythonWin doesn't appear to use the new format --- it doesn't follow the
standard Python DB API --- so if you stick with PythonWin's 'odbc' driver,
you don't have to use the "new" connection string format.


If you use mxODBC, then you probably do need to follow their approach for
creating a new connection, which might look something like,

    connect(mydsn, user=uid, passwords=pwd)


So the problem may be a nonissue after all.  *grin*


Good luck!