[英]The operation is not valid for the state of the transaction
我有一个TransactionScope()
块。 它总是卡在插入语句中。 它在活动监视器中显示为阻塞任务,因此它阻塞了 SQL 服务器,超时后,我收到此错误:
该操作对于事务的状态无效。
怎么了?
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)
{
}
这可能意味着它中止了。 您是否在交易括号内称交易完成?
try
{
using (TransactionScope scope01 = new TransactionScope(opt, span))
{
using (var sqlcon = new SqlConnection(sSqlCon))
{
//select,insert , update statements
}
scope01.Complete();
}
}
如果不调用Complete,它会自动回滚。
事务可能已超时。 检查maching.config的默认超时
<configuration>
<system.transactions>
<machinesettings maxtimeout="00:30:00" />
</system.transactions>
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.