0

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)

このエラーに関する検索情報があり、主な考えは接続が閉じられているということですが、理由がわかりませんか?

助けやアドバイスをいただければ幸いです

4

1 に答える 1

0

わかりました、問題の原因を見つけました。トランザクションタイムアウトです。System.Transaction には MaxTimeout プロパティがあり、デフォルト値は 10 分です。コードまたはアプリ/ウェブ構成を使用すると、その価値を下げることしかできません。それを増やすには、ファイルの構成セクションのENDに次のブロックを追加して、machine.config ファイルで構成する必要があります。

<system.transactions>
 <machineSettings maxTimeout="01:00:00" />
</system.transactions>
</configuration> 

関連する記事は次のとおり です。コードで System.Transactions のデフォルトのタイムアウトの 10 分をオーバーライドします

Machine.Config の maxTimeout 値が C# winform アプリで取得されない

于 2016-07-04T06:56:38.387 に答える