Excel ファイルからデータをロードする必要がある ASP.NET アプリケーションがあります。ファイルには約 20K のレコードが含まれています。アプリはファイルからデータを読み取り、各レコードをループして計算と検証を行い、各レコードを DB に挿入します。Insert メソッドが例外をスローするまで、すべてが期待どおりに機能します。エラーは、10 ~ 11 分の実行後にスローされます。注: すべてのロード プロセスは、次のように定義されたトランザクション スコープで実行されます。
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue))
SQLConnection が開かれるたびに、SQL プロファイラーを使用してこれを確認しました。DB を操作するために、Microsoft.Practices.EnterpriseLibrary.Data.Database オブジェクトを使用します。これは Insert メソッドです。
public bool InsertInspectionRide(InspectionRideBE be)
{
bool result = false;
try
{
using (System.Data.Common.DbCommand cmd = db.GetStoredProcCommand("InsertInspectionRide",
be.param1, be.param2))
{
cmd.CommandTimeout = 60000000;
be.IdRide = Convert.ToInt32(db.ExecuteScalar(cmd));
result = be.IdRide > 0;
}
}
catch (Exception ex)
{
if (ExceptionPolicy.HandleException(ex, "DAL"))
{
throw;
}
}
return result;
}
これはエラーです:
06/28/2016 10:27:14
Type : System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message :
Source :
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite :
Stack Trace : The stack trace is unavailable.
Additional Info:
MachineName : XXX
TimeStamp : 6/28/2016 7:27:14 AM
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
AppDomainName : /XXX-1-131115702788886173
ThreadIdentity : XXX
WindowsIdentity : XXXX
Inner Exception
---------------
Type : System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Invalid attempt to call Read when reader is closed.
Source : System.Data
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Boolean ReadInternal(Boolean)
Stack Trace : at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
at System.Data.SqlClient.SqlDataReader.Read()
at System.Data.SqlClient.SqlCommand.CompleteExecuteScalar(SqlDataReader ds, Boolean returnSqlValue)
at System.Data.SqlClient.SqlCommand.ExecuteScalar()
at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteScalar(IDbCommand command)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteScalar(DbCommand command)
at EnforcementService.DataAccess.InspectionRideDAL.InsertInspectionRide(InspectionRideBE be)
このエラーに関する検索情報があり、主な考えは接続が閉じられているということですが、理由がわかりませんか?
助けやアドバイスをいただければ幸いです