Here's a strange problem I'm running into on a production server. It has happened twice in the last two weeks, and this is a server that gets a lot of traffic.
We have some code in a Web Service that executes a BEGIN TRAN
, then runs a few SQL queries (two inserts followed by an update). Then at the end executes a COMMIT
. Twice now we have gotten the message in the logs:
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
Between the first two inserts and the update, we call another web service, so there could be a slight delay between the first two inserts and last update before the COMMIT
is called. Could this be causing our problem? We're running this on IIS 7 and Server 2008 R2 (all updated applied).
Originally we though it could be the app pools getting recycled, but changed that to recycle in the middle of the night. Now I'm not sure what would be causing SQL server to forget the call to BEGIN TRAN
.
This web service does get called quite a bit. Has anyone seen something like this before? I'm at a total loss at the moment...
Any help or suggestion appreciated greatly!
5条答案
按热度按时间cotxawn71#
It looks like your transaction failed, got rolled back and there is nothing to commit
example of such a thing
Now run this
Here is the error
This will run without a problem
A good article on transactions is Error Handling in SQL 2005 and Later by Erland Sommarskog
bsxbgnwa2#
My issue was I needed a BEGIN and END around my BEGIN TRAN and COMMIT TRAN.
jum4pzuy3#
BEGIN TRANS
at the top will help
nqwrtyyt4#
I had this problem as well.
Turned out, in my case, the problem was two
commit
s.The first one worked as intended. The second produced this message. Deleting the second
commit
solved the problem.piah890a5#
I had the same issue. This is what I did to solve it.
The
COMMIT TRANSACTION
request has no correspondingBEGIN TRANSACTION
After I Checked the
SQL
Query and Add aBEGIN TRAN
it will executed successfully. Here My sample code. It will work: