Using ADO in IIS

gbreed at cix.compulink.co.uk gbreed at cix.compulink.co.uk
Tue Apr 11 06:05:42 EDT 2000


> Can someone please help me use ADO from IIS.  I just purchased Mark's 
> new
> book on Win32 but his example on page #254 is for Pythonwin not for
> ASP/Python.  The ASP context requires different object creation syntax.
> I've been asking this question for over six months and no one seems to 
> know
> or care about finding a solution.

I need it to work as well.  Here's a basic script to read and return a 
table:

<%@ LANGUAGE = Python %>
<%
import win32com.client

oconn=win32com.client.Dispatch("ADODB.connection")
# add the correct fields for your database in the next line
oconn.Open ("database=*;DSN=*;ID=*;Password=*;")
objRecords, thing = oconn.Execute (
  "SELECT name, colour FROM fruit ORDER BY name")

Response.Write("<TABLE><TR>")
for objField in objRecords.Fields:
  Response.Write("<TH>"+objField.Name+"</TH>")
Response.Write("</TR>")
while not objRecords.EOF :
  Response.Write("<TR>")
  for objField in objRecords.Fields:
    Response.Write("<TD>"+objField.Value+"</TD>")
  objRecords.MoveNext()
  Response.Write("</TR>")
Response.Write("</TABLE>")

oconn.close
oconn=None
%>

Obviously you'll need this particular table in your database for it to 
work, but you should be able to adapt it.  The only gotcha I've found is 
that Execute returns a tuple.  Otherwise, it's a straight conversion from 
VBScr*pt.

> I've seen many others ask this same question over and over with no 
> resolve.
> Can we work together to finally find an ASP/ADO/Python solution.

Sure.  What problems are you having?

   Graham



More information about the Python-list mailing list