Handling Uncommitable transaction SQL SERVER

1.7k views Asked by At

I have a procedure which is of the below sort

BEGIN TRY
BEGIN TRAN
...transactins A....
   BEGIN TRY
   .... Transaction B ....
   END TRY
   BEGIN CATCH
   .... Set variables and print messages ....
   END CATCH
....Transaction C
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
...Transaction D
END CATCH

The Transaction B is throwing an error and due to this the process is going into an uncommitable state and throwing the below error. I have checked the XACT_STATE() Value it is -1

Msg 3930, Level 16, State 1, Procedure xxxxxxxx, Line 70 The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.

Is there any other way to over come this by some how skipping the transaction B and executing the transactions C

1

There are 1 answers

3
Joe Stefanelli On

The whole point of using a transaction is that the operations within it either all succeed or all fail. If you want to isolate Transaction C from the affects of the failure of Transaction B, then use separate BEGIN TRAN/COMMIT/ROLLBACK operations for each.