Using XACT_STATE

  • Hello,

    This is my first time trying to use XACT_STATE. I found this below example on BOL. My question, do we need this check - IF XACT_STATE() =1? If we are inside a catch block, it means something went wrong, and we would just do a rollback, right? Why are we checking for this above condition and doing a commit?

    Thanks.

    BEGIN TRY

    BEGIN TRANSACTION;

    DELETE FROM Production.Product WHERE ProductID = 980;

    COMMIT TRANSACTION;

    END TRY

    BEGIN CATCH

    IF (XACT_STATE()) = -1

    ROLLBACK TRANSACTION;

    IF (XACT_STATE()) = 1

    COMMIT TRANSACTION;

    END CATCH;

    GO

  • I just want to confirm your consideration. I also don't know a reason to commit a transaction if there was an error.

    Greets

    Flo

  • Bump. Anyone?

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

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