Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disappearing transactions

Status
Not open for further replies.

davidrobin

Programmer
Aug 17, 2000
50
0
0
GB
I have an interesting sistuation with transaction.

My main code looks something like this

Private sub DoStuff()
on error goto Abort

conn.begintrans

...
do lots here including calling other
functions on other forms

MoreStuff()
...

conn.committrans
exit sub
Abort:
conn.rollbacktrans
msgbox err.number
end sub

If one of the functions on another form called from this routine has an error on it, I raise the error so it is displayed using the message box in the error handler like so.

Pulbic sub MoreStuff()
on error goto Abort

...
yet more stuff here.
...

exit sub
Abort:
err.raire err.number,err.source,err.description
exit sub

Now the problem is when the error is raised to DoStuff. DoStuff errors on the conn.rollbacktrans line with
'No Transaction is active.'.

I can't unserstand it as the begintrans line is definitely getting executed.
The transaction should still be active. Is there a quirk with transactions that anyone knows of.
I really need help on sorting this out as it is messing up my app.

David
Visual Basic 6 Ent
 
I assume you're using ADO. I've never had any luck using the built-in transaction methods for the connection object. I would get the same result you did. It acts like the begin trans never happened. Do this instead:

conn.execute "begin transaction [label]"

conn.execute "commit transaction [label]"
or
conn.execute "rollback transaction [label]"

It's a good idea to add a label, so you can have nested transactions if you need them. Also, you should check the result of the execute to make sure it worked properly.



"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
I am using the DataEnvironment for connections.

What is the difference between
conn.execute "begin transaction"
and
de.cnn.begintrans

David
Visual Basic 6 Ent
 
The begintrans is built into ADO. The "begin transaction" from the connection object is done at the database level. I don't know how the ADO version functions, but I was never able to get it to work properly for me.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top