Question Transaction state check

fazal.shaikh

Member
Joined
Apr 20, 2009
Messages
6
Programming Experience
1-3
Dear Friends,

I need to check if the Current SqlTransaction object which was begin on a connection is active or not.

The reason is when an SqlException occurs it rolls back the transaction. But in catch ex as Exception block i have not written rollback. Before rolling it back I want to check if the transaction is active or note? Then only the SqlTransaction should be rolled back. other wise it shouldn't be.

Thanks in Advance.
Fazal
 
Just use a TransactionScope and then you don't have to care.
VB.NET:
Using tx As New TransactionScope
    Try
        '...

        tx.Complete()
    Catch ex As Exception
        '...
    End Try
End Using
The transaction is committed or rolled back implicitly at the End Using line, depending on whether Complete was called or not.
 

Latest posts

Back
Top