关于c#:交易超时

Transaction Timeout

我有以下异常的问题:

The transaction associated with the current connection has completed
but has not been disposed. The transaction must be disposed before the
connection can be used to execute SQL statements.

针对数据库的"调用"需要10m 53秒(经过测试,未进行交易且成功)
交易后10m后引发异常。因此,我很确定不是导致问题的代码,而是事务超时限制。

我已经看到很多人都在为这个问题而苦苦挣扎,但是我已经尝试了所有可能的解决方案,但是仍然无法成功摆脱这种异常。

我使用以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[...]
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( );
}

我添加了声明

1
2
3
<system.transactions>
    <machineSettings maxTimeout="02:00:00"/>
</system.transactions>

到%WINDIR%\\\\ Microsoft.NET \\\\ Framework64 \\\\ v4.0.30319 \\\\ Config中的machine.config
在两台机器(本地和sql-server-machine)上。

我已经没有了下一步可以尝试的想法了。有什么建议吗?


确保已修改正确的machine.config文件。

根据编译应用程序的方式(AnyCPU / x64 / x86,"首选32位"),使用的machine.config将有所不同(Framework与Framework64)。

还请确保在修改machine.config之后重新启动计算机。


一个疯狂的猜测:您是否正在运行32位应用程序?那么这可能是错误的machine.config!

%WINDIR%\\\\ Microsoft.NET \\\\ Framework \\\\ v4.0.30319

否则,我将检查在web.config或app.config

中是否覆盖此值