该操作对交易状态无效 [英] The operation is not valid for the state of the transaction
本文介绍了该操作对交易状态无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 TransactionScope()
块.它总是卡在插入语句中.它在活动监视器中显示为阻塞任务,因此它阻塞了 SQL 服务器,超时后,我收到此错误:
I have a TransactionScope()
block. It always gets stuck in an insert statement. It appears in the Activity Monitor as a Blocking Task, so it blocks the SQL server, and after the timeout, I get this error:
该操作对交易状态无效.
The operation is not valid for the state of the transaction.
怎么了?
const TransactionScopeOption opt = new TransactionScopeOption();
TimeSpan span = new TimeSpan(0, 0, 1, 30);
try
{
using (TransactionScope scope01 = new TransactionScope(opt, span))
{
using (var sqlcon = new SqlConnection(sSqlCon))
{
//select,insert , update statements
}
}
}
catch (Exception ex)
{
}
推荐答案
这可能意味着它中止了.您是否在交易括号内称交易完成?
It probably means it aborted. Did you call transaction complete within transaction bracket?
try
{
using (TransactionScope scope01 = new TransactionScope(opt, span))
{
using (var sqlcon = new SqlConnection(sSqlCon))
{
//select,insert , update statements
}
scope01.Complete();
}
}
如果不调用Complete,会自动回滚.
If it doesn't call the Complete, it will automatically rollback.
这篇关于该操作对交易状态无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文