Although it's not entirely clear from
the documentation[
^],
ROLLBACK TRANSACTION
doesn't terminate the stored procedure. The statements after the
ROLLBACK
continue to execute.
The next statement to execute will be the
COMMIT TRANSACTION
line, which will fail with an error:
Quote:
Msg 3902, Level 16, State 1, ...
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
However, this should be caught and handled by your
CATCH
block. But it would be better to put a
Return;
statement after the
ROLLBACK
, so that the procedure doesn't try to commit the transaction.
I suspect the code which is calling this stored procedure is also using a transaction, which is causing the
CATCH
block to try to roll back the
SerialNumbers
transaction which has already been rolled back. But that still doesn't produce the same error for me.
If adding the
Return;
statement doesn't fix the problem, perhaps you could show the code which is calling this procedure?