0

I have a stored procedure that may be called from a transaction. When there is an exception I want to rollback the transaction (the top-level transaction). I would like to use something like this:

...procedure definition...
BEGIN

    BEGIN TRY

        --work&logic

    END TRY

    BEGIN CATCH 
        -- An error occurred!
        IF @@TRANCOUNT > 0
            ROLLBACK
    END CATCH
END

The catch with this is, that the SQL Code Guard reports for this the warning EI020 - ROLLBACK TRANSACTION without BEGIN TRANSACTION. Is there a way to write this properly?

David Atkinson
  • 5,759
  • 2
  • 28
  • 35
user992990
  • 41
  • 5

0 Answers0