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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BeginTrans CommitTrans 2

Status
Not open for further replies.

Deadline

Programmer
Feb 28, 2001
367
US
Hi,

I have the cn.RollBackTrans in the ErrHandler area of my VB Code.

The issue here is sometimes, even before the program encounters the
Code:
cn.BeginTrans
command, there is a possibility of an error; And hence, it skips immediately to the
Code:
cn.RollBackTrans
command and I guess I am getting an error that begins like this

Object or With Block.....


The following is the error handling part I am using in my code:

Code:
ERRMAIN:
    If Err.Number = 62 Then
        Call ErrHandler("Empty Text File Present." & Chr(13) & "Please Copy the Proper Text File")
        Exit Sub
    Else
        Call ErrHandler(CStr(Now) & "-" & Err.Source & "-" & Err.Description & "-" & Err.Number)
    End If
    cn.RollbackTrans
    cn.Close
    Set cn = Nothing
    Exit Sub
End Sub




How to avoid the cn.RollbackTrans, if we haven't had cn.BeginTrans executed ?? WHat will happen if I simply don't give cn.RollBackTrans here in the error handler part ?


Thank you very much.

RR


 
Probably the easiest way to do it is to have a variable, InsideTransaction that you can set to true when you issue a Begintrans. Set it to false when you issue a committrans or rollbacktrans. Then put this in your error handler in place of the simple rollback:
Code:
If Not InsideTransaction Then 
    'there is no transaction, so don't roll it back
Else 
    cn.RollBackTrans 
    InsideTransaction = False 
End If
Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Thanks Ruari...
Precisely that is what I did. Thank you very much.

RR


 
my my my . . . what a simple solution . . . i been thinking of same problem . . .

tnx a lot . . .

Please pardon the grammar.
Not good in english.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top