【问题标题】:TransactionScope TransactionAborted Exception - BeginCommit()?TransactionScope TransactionAborted 异常 - BeginCommit()?
【发布时间】:2013-03-27 21:32:20
【问题描述】:

TimeoutException 问题。

上下文:Visual Studio 2010

问题:我偶尔(在每小时运行一次的程序上每天一次)遇到异常 我不明白。

这是个例外:

Exception message : The transaction has aborted.
Exception Source : System.Transactions
Exception Trace  :    at System.Transactions.TransactionStateAborted.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState)
   at System.Transactions.CommittableTransaction.Commit()
   at System.Transactions.TransactionScope.InternalDispose()
   at System.Transactions.TransactionScope.Dispose()
   at JDTranslation_K4_ReadEmails.Form1.ReadEmailDetails(EmailMessage emMessage, String strUserName, String strAccountName)
Exception Target : Void BeginCommit(System.Transactions.InternalTransaction, Boolean, System.AsyncCallback, System.Object)

该异常通常发生在持续 25-30 分钟的事务之后。

我已将交易设置为持续 5 小时(见下文),所以我完全不明白为什么 它可能会超时。

而且我有点担心:我知道有些数据是提交给 数据库 - 我可以相信他们都是? (几乎不可能通过 调查数据。)

程序(函数的一部分)大致如下:

//INSTANTIATE THE TRANSACTION SCOPE
TransactionOptions option = new TransactionOptions();
//SET THE ISOLATION LEVEL AND THE TIMEOUT DURATION
option.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
option.Timeout = new TimeSpan(5, 0, 0);

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option))
{
try{
// do some select/update/insert/delete stuff on both connections,
// up to perhaps 3600 actions
// some of it happens in static functions declared elsewhere in the same class scope
} // this is the line mentioned in the Exception

}

我很乐意回答我的一些问题:

为什么会发生异常?

我是否可以相信所有数据都已提交,或者 C#.NET 中是否存在允许部分提交的真正错误?

我的代码是否正确,或者我应该以不同的方式组织它来解决问题?

请帮忙!

【问题讨论】:

    标签: transactionscope


    【解决方案1】:

    您可以在 web.config 中增加超时时间。此外,尝试增加池大小。有时在长查询中它会增加最大线程限制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 1970-01-01
      相关资源
      最近更新 更多