Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = %ld, current count = %ld.

Error Message:
Msg 266, Level 16, State 2, Procedure, Line 0
Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = %ld, current count = %ld. Severity level:
16. Description:
This error message appears when you try to execute a procedure, but the transaction count before and after the EXECUTE is not identical. Consequences:
The T-SQL statement can be parsed, but causes the error at runtime. Resolution:
Error of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. You cannot run the statement this way. The transaction count before and after the EXECUTE must be identical. Versions:
All versions of SQL Server. Example(s):
IF OBJECT_ID (‘dbo.p1’) IS NOT NULL
    DROP PROCEDURE dbo.p1;
GO IF OBJECT_ID (‘dbo.p2’) IS NOT NULL
    DROP PROCEDURE dbo.p2;
GO CREATE PROCEDURE dbo.p1
AS
BEGIN TRAN
EXEC dbo.p2;
COMMIT TRAN;
GO CREATE PROCEDURE dbo.p2
AS
ROLLBACK TRAN;
GO EXEC dbo.p1; Remarks:
In the above example we try to call the procedure dbo.p2 inside dbo.p1. Because p2 rolls the transaction back that was started before p2 was called, the transaction count before and after the EXECUTE is not identical. This raises the error. ]]>

Leave a comment

Your email address will not be published.