ADO/ODBC/ASP/Python error
Mark Ainsworth
marka at sundance.com
Thu Jan 10 08:23:40 EST 2002
Jason R. Coombs wrote:
>Maybe I'm trying to use too many stacked technologies, but I think this
>should work. I would like to use Python in my ASP because VBScript doesn't
>give me the flexibility I need.
>
>I have an (access) database on the server, and an ODBC link to that database
>with the System DSN 'EnvMon'. This VBScript runs:
>--------------------------
><HTML><HEAD><TITLE>enter sample</TITLE></HEAD><BODY>
><%
>Dim conn
>
>Set conn = Server.CreateObject("ADODB.Connection")
>conn.open "Provider=MSDASQL;DSN=EnvMon"
>%>
>
>Hello World
></BODY></HTML>
>----------------------------
>and I can query the database and whatever.
>However, the equivalent Python fails:
>------------------------
><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")
>%>
>
>Hello World
></BODY></HTML>
>----------------------------------
>with the error
>
>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
>
>
>I receive the same exception if I run the commands directly from the
>interpreter. Since I am running this code on the same server with the same
>COM components, the only difference I can see is that Python is not passing
>the string parameter(s) as I expect it would to the ADODB.Connection
>component.
>
>I have tried to get the connection to work on other computers, but cannot
>seem to esablish it there, either. I have searched the web and this
>newsgroup and found nothing that hinted at this problem. Has anyone seen
>this before? Any recommendations on how I might locate the problem?
>
>Jason
>
>
Jason, here is one of my pages. It's taken about a day to figure it out
from scratch (No previous ASP experience) and the best help came from
"ASP in a Nutshell" O'Reilly ISBN 1-56592-843-1. You just have to
convert all the VBscript (yuk) to Python. It may not be the neatest code
in the world but it is a test file just to prove the viability. The
hardest part was getting the SysAdmin to install Python on the server. :-(
Take and hack to your heart's content.
Rgds
Mark Ainsworth
QC Manager
Sundance Multiprocessor Technology.
<%@ Language=Python%>
<%
objConn = Server.CreateObject("ADODB.connection")
objRS = Server.CreateObject("ADODB.RecordSet")
objConn.Open("QCforms")
objRS.Open("Select * from Equipment", objConn)
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Calibrated Eqipment List</title>
<link rel="stylesheet" href="quality2000.css" type="text/css">
</head>
<body>
<H1 class="smt">Equipment List</H1>
<table class="smt" border="1">
<tr>
<%
headings = ["Description","Serial Number","Permitted
Errors","Interval","Checking body"]
for Head in headings:
Response.Write("<td>"+Head+"</td>")
%>
</tr>
<%
while not objRS.EOF:
Response.Write("<tr>")
for Head in headings:
Response.Write("<td>")
if Head == "Description":
"""
If we are in the description section then we have to
create a link with the right values to the certificate
display page.
"""
Response.Write("<a href=""certificate.asp?type=")
Response.Write(objRS("Reference"))
Response.Write(' >')
Response.Write(objRS(Head))
if Head == "Description":
Response.Write("</a>")
Response.Write("</td>")
Response.Write("</tr>")
objRS.Move(1)
%>
</table>
</body>
</html>
<%
objRS.Close()
objConn.Close()
%>
More information about the Python-list
mailing list