0

I would like to start a transaction through a sql procedure, run other 2 procedure, and then run the first procedure with command: 'commit'. Do you believe that this could be possible? I tried but received an error. Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.

1

2 Answers 2

0

This happens because SQL Server does not really support nested transactions.

If you commit or rollback in a nested stored proc (not transaction), then you'll generate error 266 because of a @@TRANCOUNT mismatch on start and entry.

You should pair up your BEGIN TRAN and COMMITs in the same SPROC.

If there is no concept of nested transaction then you need to do rollback/commit in same sproc. You can use SET XACT_ABORT ON suppresses error 266 caused by mismatched @@TRANCOUNT.

1
-1

not sure about nested transactions in sql server but you can try this one

Begin Try
 Begin Transaction1
  Call Proc1
   Call Proc2
   Call Proc3
 Commit
 End Transaction
Catch
 Rollback
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.