-
Jul 1st, 2015, 04:01 PM
#1
Thread Starter
Hyperactive Member
BeginTrans / RollbackTrans
Can the VB6 detect if currently Transaction was begun?
I want to check it prior to perform Rollbacktrans in error hadling like following.
Error:
If (Transaction was begun) Then
cn.RollbackTrans
EndIif
-
Jul 1st, 2015, 04:23 PM
#2
Re: BeginTrans / RollbackTrans
It's your application responsibility to track whether the transaction started or not. It's not something ADO/DAO can tell you. The best way to structure this is, for example:
Code:
On Error Go To ErrHandler
cn.BeginTrans
'... your code..
cn.CommitTrans
Exit Sub
ErrHandler:
cn.RollBackTrans
-
Jul 1st, 2015, 06:54 PM
#3
Thread Starter
Hyperactive Member
Re: BeginTrans / RollbackTrans
jcis,
I did it already but I just wanted to know if there's something to check it.
Thanks!
-
Jul 1st, 2015, 09:12 PM
#4
Re: BeginTrans / RollbackTrans
Originally Posted by jdy0803
I did it already but I just wanted to know if there's something to check it.
Directly built-into ADO I can't think of something which offers such an
"I'm in a transaction"-Information.
With SQLite you could query the named TransactionStack (or simply the
TransactionStack-Counter) - but that involves other Wrapper-libs than ADO.
So, in your case I think the simplest thing you could do is, to just
introduce more than one Error-Marker (one for your normal Errorhandling,
and one - e.g. named RollBack: - for your Transaction-block.
Shortly before entering the Transaction-CodeBlock, you would have
to switch from normal ErrHandling to your additional Marker:
Code:
On Error Goto ErrHandler
'...normal code before the Transaction
On Error Goto RollBack 'switch the normal Error-JumpMarker to the one named RollBack
Cn.BeginTrans
'......DB-Transactions...
Cn.CommitTrans
On Error Goto ErrHandler 'switch back to the normal Error-JumpMarker
'...more normal code
Exit Sub
RollBack:
Cn.RollBackTrans
ErrHandler:
MsgBox Err.Description
End Sub
Olaf
-
Jul 2nd, 2015, 04:40 AM
#5
Re: BeginTrans / RollbackTrans
I use this structure coding:
Code:
Public Function SaveData(<parameters>) As Boolean
On Error GoTo ERR_HANDLER
Dim bOnTransaction As Boolean
CN.BeginTrans
bOnTransaction = True
'... code...
CN.CommitTrans
bOnTransaction = False
SaveData = True
Exit Function
ERR_HANDLER:
MsgBox "Error : " & Err.Number & " - " & Err.Description
If App.LogMode = 0 Then ' I will check for error...
Stop
Resume
End If
If bOnTransaction = True Then
CN.RollbackTrans
End If
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|