views:

207

answers:

4

I am getting the error from the application as following with SQL server 2005

"Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0"

How can i find the stage where this error raised? how can i found the missing transaction or the stored procedure where it is not committ or rollback?

+4  A: 

I don't think anything is missing. It's probably an inner stored procedure that gets called from inside a transaction (TRANCOUNT = 1), starts its own transaction (TRANCOUNT = 2) and then rolls it back. Well, it means to roll it back, but rollback affects all transactions and not only the innermost one, so the procedure screws up the execution flow.

A way to find the place depends on available tools/skills. A better way is to use SQL Profiler that shows all commands executed by an application against the server. Find out the outermost stored procedure and go through its code looking for any other procedure calls.

GSerg
If named transactions are used, you can use `ROLLBACK {transaction name}` which rolls back only the named transaction.
AakashM
No you cannot. `{transaction name}` can only be the name of the outermost transaction. You can create a savepoint though, but that's a different thing.
GSerg
Oh, my mistake, misread the docs.
AakashM
+1  A: 

The system function @@TRANCOUNT will return how many transactions you are currently in. As part of your investigation, insert PRINT @@TRANCOUNT or SELECT @@TRANCOUNT statements at appropriate places to see what is going wrong.

AakashM
A: 

you can use DBCC commands to check your database for existent faults.

masoud ramezani
A: 

that usually means that you had nested transactions and there was a ROLLBACK. you don't really provide any information about the code running, stored procedures, dynamic SQL, etc. So this is just a guess, but I would do a search for "ROLLBACK" and add PRINTs or INSERTs INTO YourErrorLogTable after each one, make sure that the content is unique enough to determine what ROLLBACK was hit. Another thing you can try is to add some TRY - CATCH blocks where you include PRINTs or INTO YourErrorLogTable in the CATCH. If you provide more details about the code being called (nested procedures, are you using try-catch blocks, dynamic sql, linq, etc.), I could give you more specific advise on how to find the problem.

KM