Tesing for Active Transaction

  • I am an application developer using VB6 with SQL Server 2000.

    Often in my code, I begin Transactions on my SQL Server database via ADO which are committed upon successful execution of the code, or rolled back in case of an error.

    In my error handler, I need to test whether the transaction is active before I roll it back, else it throws another error. Is there a way to do that in SQL?


    Regards,

    goodguy

    Experience is a bad teacher whose exams precede its lessons

  • select @@trancount

    Incremented when you start a new transaction, decremented when it's committed or roll'd back. If 0, no transactions for this connection.

  • Rather than retrieve the value of @@trancount, test in the VB code and send a rollback if greater than 0, just always send this SQL:

    IF @@trancount > 0 rollback

    Simple and idiot proof.

    SQL = Scarcely Qualifies as a Language

  • Thanks to each of you; now, if I use this in VB6 simply as it is, will it work?:

    Cnn.Execute "If @@trancount > 0 RollBack"

    (where 'cnn' is my ADO Connection)


    Regards,

    goodguy

    Experience is a bad teacher whose exams precede its lessons

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply