0

コントローラーでこのエラーが発生しています

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: There is already an open DataReader associated with this Connection which must be closed first.
   at MySql.Data.MySqlClient.MySqlCommand.CheckState()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   --- End of inner exception stack trace ---
   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)
   at System.Data.Objects.DataClasses.EntityReference`1.Load(MergeOption mergeOption)
   at System.Data.Objects.DataClasses.RelatedEnd.Load()
   at System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad()
   at System.Data.Objects.DataClasses.EntityReference`1.get_Value()
   at Timee.fingerprint.get_employee() in C:\Users\MyNameDesktop\Time\Timee\AModel.Designer.cs:line 2234
   at Timee.BundyForm.verificationControl_OnComplete(Object Control, FeatureSet FeatureSet, EventHandlerStatus& EventHandlerStatus) in C:\Users\MyName\Desktop\Time      \Timee\BundyForm.cs:line 82
   at DPFP.Gui.Verification.VerificationControl.<>c__DisplayClass2.<relay_OnComplete>b__0()

コントローラ:

 void verificationControl_OnComplete(object Control, DPFP.FeatureSet FeatureSet, ref DPFP.Gui.EventHandlerStatus EventHandlerStatus)
    {
        clearInfoBoxTimer.Stop();

        DateTime entryTime = DateTime.Now;

        DPFP.Verification.Verification ver = new DPFP.Verification.Verification();
        DPFP.Verification.Verification.Result res = new DPFP.Verification.Verification.Result();

        employee employees = null;
        foreach (fingerprint fingerPrint in this.db.fingerprints)
        {
            DPFP.Template template = new DPFP.Template();
            template.DeSerialize(fingerPrint.data);
            ver.Verify(FeatureSet, template, ref res); 
            if (res.Verified)
            {
                employees = fingerPrint.employee; //Im GETTING AN ERROR HERE
                break;
            }
        }
     }

私が読んだいくつかのフォーラムに基づいてmultipleactiveresultsets=True;、webconfigに追加する必要があります。しかし、私の場合、それをサポートしていない MYSQL を使用しているため、適用できません。これを機能させる他の方法はありますか?みんな助けてください、ありがとう。

検証モデル

// Summary:
//     Performs the system function of fingerprint verification, which is a one-to-one
//     comparison of a fingerprint feature set with a fingerprint template produced
//     at enrollment that returns a decision of match or non-match.
public class Verification
{
    // Summary:
    //     Use this value to specify the default FAR threshold
    public const int ProbabilityNotSet = -1;

    // Summary:
    //     Initializes a new instance of the Verification class for comparing a fingerprint
    //     feature set with a fingerprint template using the default value of the false
    //     accept rate (FAR)
    public Verification();
    //
    // Summary:
    //     Initializes a new instance of the Verification class for comparing a fingerprint
    //     feature set with a fingerprint template and assigns the value of the FAR
    //
    // Parameters:
    //   FARRequested:
    //     Value of the requested FAR
    public Verification(int FARRequested);

    // Summary:
    //     Returns or assigns the requested false accept rate (FAR)
    public int FARRequested { get; set; }

    // Summary:
    //     Performs fingerprint verification and returns the comparison decision based
    //     on the default FAR threshold
    //
    // Parameters:
    //   FeatureSet:
    //     A DPFP.FeatureSet object
    //
    //   Template:
    //     A DPFP.Template object
    //
    // Returns:
    //     Verification result object
    public static Verification.Result Verify(FeatureSet FeatureSet, Template Template);
    //
    // Summary:
    //     Performs fingerprint verification and returns the comparison decision based
    //     on the specified FAR threshold
    //
    // Parameters:
    //   FeatureSet:
    //     A DPFP.FeatureSet object
    //
    //   Template:
    //     A DPFP.Template object
    //
    //   FARRequested:
    //     False Accept probability threshold or ProbabilityNotSet to use the default
    //     threshold
    //
    // Returns:
    //     Verification result object
    public static Verification.Result Verify(FeatureSet FeatureSet, Template Template, int FARRequested);
    //
    // Summary:
    //     Performs the system function of fingerprint verification and specifies a
    //     comparison decision based on the FAR set by the FARRequested property
    //
    // Parameters:
    //   FeatureSet:
    //     A DPFP.FeatureSet object
    //
    //   Template:
    //     A DPFP.Template object
    //
    //   Result:
    //     A DPFP.Verification.Result object
    public void Verify(FeatureSet FeatureSet, Template Template, ref Verification.Result Result);

    // Summary:
    //     Represents the results of a fingerprint verification operation.
    public class Result
    {
        // Summary:
        //     Default c-tor
        public Result();

        // Summary:
        //     Returns or assigns the value of the achieved FAR for a comparison operation.
        public int FARAchieved { get; set; }
        //
        // Summary:
        //     Returns or assigns the comparison decision, which indicates whether the comparison
        //     of a fingerprint feature set and a fingerprint template resulted in a decision
        //     of match or non-match. This decision is based on the value of the FARRequested
        //     property
        public bool Verified { get; set; }
    }
}
4

6 に答える 6

1

res のデータ型は何ですか? 指紋とはどのようなデータ型ですか?

結果にさらにコンテキストを与える必要があるかもしれませんが、ADO.NET 接続を返すのではなく、データセット/データアダプターを返す必要があるようです。fingerPrint.employee はおそらく同じ基になる接続を使用しますが、最初のリーダーを閉じていないため、エラー メッセージが表示されます。

この戦略を実装すると、基盤となるデータベース インスタンスから切り離すことができます。

したがって、データベース層は内部で IDataReader を使用し、DB 接続を開くことを心配することなく、上位層が反復処理できる DataSet または DataAdapter を返します。

于 2013-07-19T11:16:24.893 に答える
1

私は今、自分の問題に対する答えを見つけることができました。これが私の実用的なソリューションです

 void verificationControl_OnComplete(object Control, DPFP.FeatureSet FeatureSet, ref DPFP.Gui.EventHandlerStatus EventHandlerStatus)
    {
        clearInfoBoxTimer.Stop();

        DateTime entryTime = DateTime.Now;

        DPFP.Verification.Verification ver = new DPFP.Verification.Verification();
        DPFP.Verification.Verification.Result res = new DPFP.Verification.Verification.Result();

        employee employees = null;
        foreach (fingerprint fingerPrint in this.db.fingerprints)
        {
            DPFP.Template template = new DPFP.Template();
            template.DeSerialize(fingerPrint.data);
            ver.Verify(FeatureSet, template, ref res); 
            if (res.Verified)
            {
                db.Connection.Close(); //I close the connection first
                db.Connection.Open(); // then I open it again

                employees = fingerPrint.employee; 
                break;
            }
        }
     }

ここの人々の提案と私が読んだいくつかのフォーラムに基づいて、最初に開いているリーダーを閉じてから、もう一度開く必要があります。どうやってそれを行うかを考えるのに時間がかかりましたが、ついに見つけることができました。これは私が自分の問題を最も簡単な方法で解決する方法です。他の解決策があるかどうかはわかりません。しかし、少なくともこれで私の問題は解決しました。それでも、私を助けようと最善を尽くしてくれたここの人々にとても感謝しています。君たちありがとう。:)

于 2013-07-23T09:39:41.567 に答える
1

以下のコードは役に立ちますか?

foreach (fingerprint fingerPrint in this.db.fingerprints)
{
    using(fingerprint)
    {
        DPFP.Template template = new DPFP.Template();
        template.DeSerialize(fingerPrint.data);
        ver.Verify(FeatureSet, template, ref res); 
        if (res.Verified)
        {
            employees = fingerPrint.employee; //Im GETTING AN ERROR HERE
            break;
        }
    }
}
于 2013-07-19T10:57:22.223 に答える
1

データリーダー内でデータリーダーを開くことはできません。(通常はネストされたループ内に、開いているリーダーがある場合、リーダーを開くことはできません)。

会社として、私たちは過去にこの問題にかなり遭遇しました。多くの調査を行った結果、目的のために、データ接続の構造を再考することにしました。

最初に開いているリーダーを閉じてから、次のリーダーを開く必要があります。このように、クラス オブジェクトをトップ レベル ループの「ストレージ」として使用し、そのオブジェクトに必要なデータを入力して、よりオブジェクト指向のコードを記述します。

リーダーを閉じます。

一時オブジェクトをステップ実行し、リーダーを開いてさらにデータを取得します。

洗って、すすいで、繰り返します。

これは私たちにとってうまく機能しています。

PS、テーブル結合をより有効に活用することで、ネストされた読み取りループを排除することもできます。

于 2013-07-19T11:09:48.687 に答える
0

foreach を使用してフィンガープリントを反復処理する場合、接続を開いたままにします。解決策の 1 つは、フィンガープリントに対して ToList() を呼び出すことです。これにより、すべてのフィンガープリントが取得されてリストに追加され、接続が閉じられます。その後、 foreach を使用してリストを反復処理し、リスト内の各項目に対して追加のクエリを実行できます。例:

foreach (fingerprint fingerPrint in this.db.fingerprints.ToList())

この質問には他にもいくつかの答えがあります:

Entity Framework: このコマンドに関連付けられた開いている DataReader が既に存在します

于 2016-12-15T07:58:09.987 に答える