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.



Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |