ADO/ODBC/ASP/Python error

Steve Holden sholden at holdenweb.com
Tue Jan 8 12:58:18 EST 2002


"Jason R. Coombs" <jaraconospam at jaraco.com> wrote in message
news:a1f6lf$c13$1 at sass2141.sandia.gov...
> WaldekO,
>
> I have tried many different strings... and as you can see with the
VBScript
> example, the string I used does work, just not in Python.  Thanks for the
> link.  I did try the examples on there (altered for my file locations, and
> they don't work either).  Indeed, I get the same error.
>
> Any other suggestions?
>
> Jason
>
>
> "waldekO" <osuchw at ecn.ab.ca> wrote in message
> news:c5b3dbee.0201071850.7dcf0b56 at posting.google.com...
> > "Jason R. Coombs" <jaraconospam at jaraco.com> wrote in message
> news:<a1dal3$e4t$1 at sass2141.sandia.gov>...
> > >>>>>>>>>>>>>>>snip
> > > > <HTML><HEAD><TITLE>enter sample</TITLE></HEAD><BODY>
> > > <%@ language=Python %>
> > > <%
> > > from win32com import client
> > >
> > > conn = client.Dispatch("ADODB.Connection")
> > > conn.open ("Provider=MSDASQL;DSN=EnvMon")
> > > %>
> > >
> > > Error Type: Python ActiveX Scripting Engine (0x80020009)
> > > Traceback (innermost last): File "<Script Block >", line 4, in ?
> conn.open
> > > ("Provider=MSDASQL;DSN=EnvMon") File "C:\Program
> > > Files\Python\win32com\client\dynamic.py", line 432, in __getattr__
raise
> > > pythoncom.com_error, details COM Error: [Microsoft][ODBC Driver
Manager]
> > > Data source name not found and no default driver specified
> > >>>>>>>>>> snip
> > > Jason
> >
> > Error message sugests that the connection string is not in correct
format
> > See http://www.e-coli.net/pyado.html for a nice introduction to ADO and
> Python
> >
This works for me (take care with case, by the way):

>>> conn = client.Dispatch("ADODB.Connection")
>>> conn.Open("DSN=HoldenWebSQL")
>>> r = conn.Execute("SELECT * FROM StdPage")
>>> rr = r[0].GetRows()
>>> len(rr)
8
>>> rr[0]
(u'consult', u'contact', u'ERROR', u'expertise', u'ffx', u'hardware',
u'home', u'ltree', u'python', u'rates', u'technol', u'wcb')

Note also that, due to differences in storage order, GetRows() returns
columns, which can be somewhat confusing if you're not ready for it. So the
rr[0] above is actually the content of the first column across all table
rows. Unless you really want to use ADO, why not consider using a DB
API-conformant ODBC driver and doing your database work in Pure Python? This
will work fine under Active Scripting.

[Alex Martelli will now tell you why ADO is superior, right, Alex?]

regards
 Steve





More information about the Python-list mailing list