TimeoutException の問題。
コンテキスト: Visual Studio 2010
問題: ときどき (1 時間に 1 回実行されるプログラムで 1 日に 1 回程度) 理解できない例外が発生します。
これは例外です:
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 に部分的なコミットを可能にするバグが本当にあるのでしょうか?
私のコードは正しいですか、それとも問題を回避するために別の方法で編成する必要がありますか?
助けてください!