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 中数字范围的通配符

使用前缀和干扰词的 SQL Server 全文搜索

c# - 样式之间的淡入淡出过渡

c# - 将多个列表框项目添加到数据库

mysql - 格式化mysql中的日期

mysql - 查询日期范围内所需的汽车

sql-server - 避免将用户存储过程命名为 SP% 或 SP_%

c# - WinForms 中的自定义工具提示控件

c# - 在 C# 中使用非托管 dll

sql - 这些 SQL UPDATE 语句中的哪一个会更快?