SA0152 : THROW statement appears as a transaction name in ROLLBACK TRANSACTION
The topic describes the SA0152 analysis rule.
THROW statement appears as a transaction name in ROLLBACK TRANSACTION
The rule checks for THROW statement appearing as a transaction name in ROLLBACK TRANSACTION statement.
The THROW statement is not a reserved keyword and is acceptable as a transaction name identifier.
This may lead to a problem in a scenario when a ROLLBACK TRANSACTION statement is a followed by a THROW statement.
If the ROLLBACK TRANSACTION statement is not followed by the semicolon (;) statement terminator, the THROW statement will be recognized as a transaction_name parameter provided to the ROLLBACK TRANSACTION statement.
This example code works as expected:
1BEGIN TRY 2 BEGIN TRANSACTION 3 SELECT 1/0 4 COMMIT TRANSACTION 5 END TRY 6BEGIN CATCH 7 IF XACT_STATE() <> 0 ROLLBACK TRANSACTION; 8 THROW 9END CATCH
This code generates a runtime error:
Cannot roll back THROW. No transaction or savepoint of that name was found.
1BEGIN TRY 2 BEGIN TRANSACTION 3 SELECT 1/0 4 COMMIT TRANSACTION 5END TRY 6BEGIN CATCH 7 IF XACT_STATE() <> 0 ROLLBACK TRANSACTION 8 THROW 9END CATCH
The rule has a Batch scope and is applied only on the SQL script.
Rule has no parameters.
The rule does not need Analysis Context or SQL Connection.
1BEGIN TRY 2BEGIN TRANSACTION 3SELECT 1/0 4COMMIT TRANSACTION 5END TRY 6BEGIN CATCH 7IF XACT_STATE() <> 0 ROLLBACK TRANSACTION; 8THROW 9END CATCH 10 11 12BEGIN TRY 13BEGIN TRANSACTION 14SELECT 1/0 15COMMIT TRANSACTION 16END TRY 17BEGIN CATCH 18IF XACT_STATE() <> 0 ROLLBACK TRANSACTION 19THROW 20END CATCH
|1||SA0152 : THROW statement will be considered as a transaction name due to a missing semicolon statement terminator after ROLLBACK TRANSACTION statement.||18||30|
© Ubitsoft Ltd. All Rights Reserved.