From: Mark Carter on
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?
From: Tim Roberts on
Mark Carter <alt.mcarter(a)googlemail.com> wrote:
>
>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'")

Well, that's not the EXACT code, because that's clearly not line 64 in the
script above. Do you actually have the file path hardcoded, as in your
example? Or are you building it up from strings?

Does the net share exist at the time you run this?

You might print conn.ConnectionString just before the Execute.
--
Tim Roberts, timr(a)probo.com
Providenza & Boekelheide, Inc.