• Register
0 votes
66 views

Problem :

My Stored Procedure is giving me following error
transaction count after execute indicates a mismatching number of begin and commit statements
6 5 3
6,930 points

1 Answer

0 votes

Solution :

This usually happens when one transaction is started and either it is not committed or it is not rolledback.

If the error comes in your stored procedure then it will lock the database tables as the transaction is not completed due to some runtime errors occuring in the absence of exception handling. So to avoid getting such errors you can use the Exception handling as shown below. 

SET XACT_ABORT ON
SET NoCount ON
Begin Try 
     BEGIN TRANSACTION 
        //Insert ,update queries    
     COMMIT
End Try 
Begin Catch 
     ROLLBACK
End Catch

Further Readings :

https://docs.microsoft.com/en-us/sql/t-sql/statements/set-xact-abort-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15

9 7 4
38,600 points

Related questions

0 votes
1 answer 79 views
79 views
Problem : I am facing following error with the below query in SQL Server 2012. An expression of non-boolean type specified in a context where a condition is expected, near 'RETURN'. SQL Query: CREATE FUNCTION [dbo].[GetMYPMResources](@UserResourceNo ... JOIN JobTask t ON t.JobTaskNo = m.JobTaskNo WHERE t.TaskManagerNo = @UserResourceNo OR t.AlternateTaskManagerNo = @UserResourceNo ) RETURN END
asked Dec 4, 2019 alecxe 7.5k points
0 votes
1 answer 11 views
11 views
Problem: I am a beginner to sql. I have the 123MB sql file which I am trying to execute on my local PC. But I am facing the below error: Cannot execute script: Insufficient memory to continue the execution of the program. Whenever I click on Ctlr+E then it ... above error. I have tried to fix the above sql error with the help of online tutorials but they were not useful in fixing the error.
asked Aug 28 Raphael Pacheco 4.9k points
1 vote
1 answer 39 views
39 views
Problem : My task is to send email with the file attachments also this attachment must come from the image type data field. If I try to run the below code in both the query window and the stored procedure but my email was not sent and in the query window I can only see ... = 1,     @query_no_truncate = 1; I need to send email but still unable to do so. I am looking for help in fixing the issue.
asked May 6 stewart 4k points
0 votes
2 answers 93 views
93 views
Problem: A(n) ____ in a class diagram indicates public access?
asked Apr 12 ArifulIslam 5.7k points