win32com sql update problem

Mark Carter alt.mcarter at googlemail.com
Tue May 11 06:40:03 EDT 2010


Consider the following snippet of code:

import win32com.client

DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=M:\\Finance\\camel\
\camel.mdb;'
conn.Open(DSN)
cursor = conn.Execute("UPDATE tblInvoice SET InvComments='Python'
WHERE InvBillingPeriod = 'April 2010' AND InvJobCode = '2169'")
rows = cursor.Affected_Rows()
print rows
conn.Close()

I am using Python 2.6.5, and pywin32. If I try to run it, I get the
response:
Traceback (most recent call last):
  File "C:/Users/mcarter/tacc/pypms/post.py", line 79, in <module>
    AdjustPms(d)
  File "C:/Users/mcarter/tacc/pypms/post.py", line 64, in AdjustPms
    cursor = conn.Execute("UPDATE tblInvoice SET InvComments='Python'
WHERE InvBillingPeriod = 'April 2010' AND InvJobCode = '2169'")
  File "<COMObject ADODB.Connection>", line 3, in Execute
  File "C:\Python26\lib\site-packages\win32com\client\dynamic.py",
line 272, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
u'Microsoft JET Database Engine', u"Cannot open database ''.  It may
not be a database that your application recognizes, or the file may be
corrupt.", None, 5003049, -2147467259), None)

I have used the same DNS to retrieve data from the database using
SELECT statements, so I'm at a loss to figure out what's going wrong.
It seems to think the database name as an empty string. I'm not sure
if that's the root cause of the problem, though. Any ideas?



More information about the Python-list mailing list