c# - 事务超时

标签 c# sql sql-server transactions

我遇到以下异常问题:

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.

针对数据库的“调用”需要 10 分钟 53 秒(在没有事务的情况下测试并成功) 对于事务,它会在 10m 后抛出异常。所以我很确定这不是产生问题的代码,而是事务超时限制。

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

我使用以下代码:

[...]
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> 

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

我已经想不出接下来可以尝试什么了。有什么建议吗?

最佳答案

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

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

否则我会检查这个值是否在 web.config 或 app.config 中被覆盖

关于c# - 事务超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21729890/

相关文章:

sql - SQL Server 2008中如何描述表?

c# - Entity Framework 查询多对多关系

c# - ComboBox 和 SelectedItem 下拉菜单设置

c# - 在设计时获取文件的相对路径

c# - C#中的TIFF文件解析

使用 Borland Delphi 远程查询 SQL Server 2005

sql - 如何将星期(200851)转换为日期(2008-12-27)?

C#:Base64编码

sql - 更新大型表的主表和子表的主键

c# - 使用 SqlConnectionStringBuilder 指定端口?