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();