这是我在生产服务器上遇到的一个奇怪的问题。过去两周内发生了两次这种情况,并且该服务器的流量很大。
我们在 Web 服务中有一些代码执行 BEGIN TRAN
,然后运行一些 SQL 查询(两次插入,然后更新)。然后最后执行COMMIT
。现在我们已经在日志中收到两次消息:
COMMIT TRANSACTION 请求没有对应的 BEGIN TRANSACTION。
在前两次插入和更新之间,我们调用另一个 Web 服务,因此在调用 COMMIT
之前,前两次插入和最后一次更新之间可能会有轻微的延迟。这会导致我们的问题吗?我们在 IIS 7 和 Server 2008 R2 上运行此程序(已应用所有更新)。
最初我们认为这可能是应用程序池被回收,但将其更改为在半夜回收。现在我不确定什么会导致 SQL Server 忘记对 BEGIN TRAN
的调用。
这个网络服务确实被频繁调用。有人见过这样的事情吗?我现在完全不知所措......
非常感谢任何帮助或建议!
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)
看起来你的事务失败了,被回滚了,没有什么可以提交的
例子
现在运行这个
这是错误
这将运行没有问题
关于事务的好文章是SQL 2005 及更高版本中的错误处理 作者:Erland Sommarskog
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
我的问题是我需要一个 BEGIN TRAN 和 COMMIT TRAN 周围的 BEGIN 和 END 。
My issue was I needed a BEGIN and END around my BEGIN TRAN and COMMIT TRAN.
BEGIN TRANS会有帮助
顶部的
BEGIN TRANS
at the top will help
我也有这个问题。
结果,就我而言,问题是两个
提交
。第一个按预期工作。第二个产生了这个消息。删除第二个
提交
解决了问题。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.我有同样的问题。这就是我所做的来解决它。
COMMIT TRANSACTION
请求没有相应的BEGIN TRANSACTION
在我检查
SQL
查询并添加BEGIN TRAN
后,它将执行成功。这是我的示例代码。它将起作用: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: