py2exe + win32com + DAO

T

Trevor

I have a Python code module that adds records to a MS Access
database. The following line of code executes successfully when the
code module is run as a Python script:

daoEngine = win32com.client.Dispatch(r'DAO.DBEngine.36')

It also runs successfully when the Python script is compiled and run
as an executable using the Py2exe utility. However, when the compiled
executable is called from VBA using the win32 CreateProcess function,
the preceding code produces this output:

!!python/name:pywintypes.com_error ''

What is causing this error?
 
D

David Lyon

Maybe VB is opening the table in Exclusive mode... then when you
are opening it as a subprocess, it's already locked.

It's possible the win32com module is not giving you a very
descriptive error message.

Try running your process while vb is running at the same time
with the database open and if you get the same error then it
might confirm my assertion.

Otherwise it is likely that it is something else.
 
T

Trevor

I do not believe your assertion applies to the following line of code:

daoEngine = win32com.client.Dispatch(r'DAO.DBEngine.36')

The preceding code snippet instantiates a COM object and is
prerequisite to creating a reference to a specific database:

daoDB = daoEngine.OpenDatabase(dbname)

As the compiled Python module executes successfully when invoked from
a command-line but not when invoked using the win32 CreateProcess
function, I suspect that one or more of the arguments to CreateProcess
is preventing successful execution. I will investigate this further
(possibly on a win32 forum); however, is it possible to obtain more
verbose error output from Python modules? The error message in the
original post was generated from:

print sys.exc_info()[0]
 
D

David Lyon

I do not believe your assertion applies to the following line of code:

daoEngine = win32com.client.Dispatch(r'DAO.DBEngine.36')

It doesn't. I'm simply suggesting that it is possible you are opening
the database in Access or something in Administrator/dba mode. That
could be causing an exclusive lock on the database so that no sub
task can then open it.

i have seen this on old versions of Access.

To provide excellent performance, microsoft used to load the whole
database into memory if it could. And just operate mostly from there.

is it possible to obtain more
verbose error output from Python modules? The error message in the
original post was generated from:

print sys.exc_info()[0]

possibly but i'm not sure how...

David
 
T

Trevor

I think the problem I am experiencing bears a resemblance to the
content of this post:

http://mail.python.org/pipermail/python-list/2001-February/071421.html

Does anyone know what the GUID for the DAO 3.6 library is (or can
explain how I can find it)?

I do not believe your assertion applies to the following line of code:
daoEngine = win32com.client.Dispatch(r'DAO.DBEngine.36')

It doesn't. I'm simply suggesting that it is possible you are opening
the database in Access or something in Administrator/dba mode. That
could be causing an exclusive lock on the database so that no sub
task can then open it.

i have seen this on old versions of Access.

To provide excellent performance, microsoft used to load the whole
database into memory if it could. And just operate mostly from there.
is it possible to obtain more
verbose error output from Python modules?  The error message in the
original post was generated from:
print sys.exc_info()[0]

possibly but i'm not sure how...

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top