0

ASP.NET は初めてです。USING ステートメントを使用するタイミングがわかりません。以下の例のコードで試してみると。永遠に時間がかかり、タイムアウトすることもあります。使用せずに実行すると、正常に動作します。

誰かが USING ステートメントを明確にしてくれませんか? いつ使用すべきか、いつ使用すべきでないか。

このコードは永遠に時間がかかり、タイムアウトしました。...ここにいくつかのコードがあります。DB接続を開く 実行....

cmdinsert.CommandText = insertcommand;
cmdinsert.ExecuteNonQuery();

Using (SqlCommand command = new SqlCommand("Import_EvaluationMatch", connSQL, trans))
    {
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add("@RefNum", SqlDbType.Int).Value = RefNum;
    command.ExecuteNonQuery();
    }
trans.Commit();
connSQL.Close();

Response.Write("Import Successfully");
Response.Redirect("Default.aspx");
Response.End();

USING ステートメントを削除しました。正常に動作します。

... Some codes up here. Open DB Connection Execute....
cmdinsert.CommandText = insertcommand;
cmdinsert.ExecuteNonQuery();


// --- Now calling the stored procedure to process all this imported items.
SqlCommand command = new SqlCommand("Import_EvaluationMatch", connSQL, trans);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add("@RefNum", SqlDbType.Int).Value = RefNum;
    command.ExecuteNonQuery();
trans.Commit();
connSQL.Close();
4

1 に答える 1

1

ステートメントにはusing時間がかかりません。時間がかかっているのは、のクリーンアップですSqlCommandusingステートメントを使用すると、クリーンアップはインラインで行われます。使用しない場合、ガベージ コレクターが決定するたびにクリーンアップがランダムに行われます。

「今支払うか、後で支払うか」のケースです。

問題は、Import_EvaluationMatchストアド プロシージャに時間がかかりすぎることです。

于 2013-10-01T21:41:52.477 に答える