[python-win32] driving MS Access from python
Phill Atwood
me at phillatwood.name
Tue Mar 14 00:54:07 CET 2006
> No, you don't need mxODBC, although I'm curious to know what led you
> to believe that.
http://phplens.com/lens/adodb/adodb-py-docs.htm#databases
I guess maybe this link was referring to PHP ...
Well, painfully I'm making some progress. And I appreciate your help in
this. I think my previous problem was because I was doing
rs.Open(sqlstmt)
instead of:
rs.Open(sqlstmt, conn)
> To execute a generic SQL statement, you create an ADODB.Command object
> and connect it to the Connection:
>
> cmd = win32com.client.Dispatch("ADODB.Command")
> cmd.ActiveConnection = conn
> cmd.CommandText = "SELECT COUNT(*) FROM committees;"
> rs = cmd.Execute[0]
>
>
> Now rs is a recordset.
Now, I've got your above example working. Almost. For me
rs = cmd.Execute[0]
failed with
TypeError: unsubscriptable object
However, trying this variation:
(rs, result) = cmd.Execute()
did work. Problem is when I then try
data = rs.GetRows()
I get
Traceback (most recent call last):
File "<pyshell#59>", line 1, in -toplevel-
data = rs.GetRows()
File
"C:\Python24\lib\site-packages\win32com\gen_py\2A75196C-D9EB-4129-B803-931327F72D5Cx0x2x8.py",
line 2333, in GetRows
, Start, Fields)
File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line
446, in _ApplyTypes_
return self._get_good_object_(
com_error: (-2147352567, 'Exception occurred.', (0, 'ADODB.Recordset',
'Operation is not allowed when the object is closed.',
'C:\\WINDOWS\\HELP\\ADO270.CHM', 1240653, -2146824584), None)
I feel so tantillizingly close...
Phill
More information about the Python-win32
mailing list