3

ASP.NETWebサイトがあります。ページをリクエストすると、ほとんどの場合は機能しますが、HttpUnhandledExceptionが発生することがあります。

エラーをログに記録しようとしましたが、エラーメッセージから問題を解決できません。

スタックトレース:

at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.default_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\4e215a3c\72ef69da\App_Web_ylvnbciw.6.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

データ:

System.Collections.ListDictionaryInternal

BaseException:

System.InvalidOperationException: The connection was not closed. The connection's current state is open.
   at DbCategory.getParentCategories()
   at _Default.Page_Load(Object sender, EventArgs e)
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

TargetSite:

Boolean HandleError(System.Exception)

私はそれが私のセッションと変数の取得に関するものだと思っていますが、それについてはよくわかりません。誰かがそれが何であるかについての考えを持っていますか?

4

3 に答える 3

1

Such errors are not because of wrong disposing - The connection was NOT closed.

Such error can be then you use SqlConnection in the static class or method which holds open connection, and after that - in not-static, and in this moment exception can occur.


Update: Well, this method is not very save - it do exactly that I was talking about - he creates connection, but never releases it. SqlConnection is very heavy object, and you should dispose it right after you get or set your data.

You should rewrite your logic - create one connection per page or per operation, and you should never store the connection in your classes.

If this is impossible for you, use the lock statement for ensure singleton, like this:

private static object singleton;

lock (singleton)
{
    // Some manipulations with your server
}
于 2010-04-20T17:50:09.573 に答える
1

ブロックの使用では、Db オブジェクト (DbConnection、DbCommand、リーダー、アダプターなど) を使用することをお勧めします。

これにより、オブジェクトの使用が終了したときにオブジェクトが常に破棄されるようにすることで、この種のことの 99% が発生するのを防ぐことができます。

于 2010-04-20T17:33:56.550 に答える
0

VMAtm: サイトのユーザーがますます増えた後、例外がより多く表示されるため、何かが得られたのかもしれません。シングルトンメソッドを使用してデータベース接続を保持する静的クラスがあります...

public static SqlConnection getDbConnection() 
{ 
    if (sqlConn == null) 
    { 
        source = "data source=..."; 
        sqlConn = new SqlConnection(source); 
    }
    return sqlConn; 
}

このメソッドは完全に保存されていますか?

すべてのデータベース呼び出しは、静的メソッドを使用して抽象クラスで呼び出され、これらの抽象クラスはシングルトン メソッドから db 接続を取得しています。

于 2010-04-20T18:52:03.433 に答える