MS Access (Jet) transactions, workspaces & scope
Posted
by Eric G
on Stack Overflow
See other posts from Stack Overflow
or by Eric G
Published on 2010-05-25T01:17:53Z
Indexed on
2010/05/25
1:21 UTC
Read the original article
Hit count: 275
I am having trouble with committing a transaction (using Access 2003 DAO). It's acting as if I never had called BeginTrans -- I get error 3034 on CommitTrans, "You tried to commit or rollback a transaction without first beginning a transaction"; and the changes are written to the database (presumably because they were never wrapped in a transaction). However, BeginTrans is run, if you step through it.
- I am running it within the Access environment using the DBEngine(0) workspace.
- The tables I'm updating are all opened via a Jet database connection (to the same database) and updated using DAO.Recordset.update.
- The connection is opened before starting BeforeTrans.
- I'm not doing anything weird in the middle of the transaction like closing/opening connections or multiple workspaces etc.
- There is one nested transaction level (basically it's wrapping multiple transacted updates in an outer transaction, so if any fail they all fail). The inner transactions run without errors, it's the outer transaction that doesn't work.
Here are a few things I've looked into and ruled out:
The transaction is spread across several methods and BeginTrans and CommitTrans (and Rollback) are all in different places. But when I tried a simple test of running a transaction this way, it doesn't seem like this should matter.
I thought maybe the database connection gets closed when it goes out of local scope, even though I have another 'global' reference to it (I'm never sure what DAO does with dbase connections to be honest). But this seems not to be the case -- right before the commit, the connection and its recordsets are alive (I can check their properties, EOF = False, etc.)
My CommitTrans and Rollback are done within event callbacks. (Very basically, a parser program is throwing an 'onLoad' or 'onLoadFail' event at the end of parsing, which I am handling by either committing or rolling back the inserts I made during processing.) However, again, trying a simple test, it doesn't seem like this should matter.
Any ideas why this isn't working for me?
Thanks.
© Stack Overflow or respective owner