我遇到了以下异常问题:
当前连接关联的事务已完成,但未被处理。在使用连接执行SQL语句之前必须处理事务。
对数据库的“调用”需要10分53秒的时间(在没有事务的情况下测试并成功),而有事务时,在10分钟后抛出异常。因此,我相当确定问题不是由代码产生,而是由于事务超时限制引起的。
我看到很多人都困扰于这个问题,但我尝试了所有可能的解决方案,但仍然没有成功摆脱这个异常。
我使用以下代码:
[...]
TransactionOptions transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = IsolationLevel.Snapshot;
transactionOptions.Timeout = new TimeSpan( 0, 0, 30, 0, 0 );
using( var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions) )
{
foreach (var selector in GetDataContext().sp_GetChangedSelectors(changeSet))
{
// xml-result will be stored in a file
}
// multiple other SP calls the same way
scope.Complete( );
}
我添加了这个语句
<system.transactions>
<machineSettings maxTimeout="02:00:00"/>
</system.transactions>
需要将machine.config文件复制到%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\Config目录下的两台机器(本地和SQL服务器)。
我已经没有更多的想法可以尝试了,有任何建议吗?