代码之家  ›  专栏  ›  技术社区  ›  jweber

HttpUnhandledException ASP.NET

  •  3
  • jweber  · 技术社区  · 16 年前

    我有一个ASP.NET网站。如果我请求一个页面,它大多数时候都能工作,但有时会出现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
    

    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)
    

    目标站点:

    Boolean HandleError(System.Exception)
    

    我知道这和我的会话og get变量有关,但我不确定。有人知道会是什么吗?

    3 回复  |  直到 16 年前
        1
  •  1
  •   VMAtm    16 年前

    这样的错误不是因为错误的处理-连接没有关闭。

    这样的错误可以在静态类或方法中使用SqlConnection来保持打开的连接,然后-在非静态中,此时会发生异常。


    更新: SqlConnection是一个非常重的对象,您应该在获取或设置数据后立即处理它。

    您应该重写您的逻辑-为每页或每个操作创建一个连接,并且不应该将连接存储在类中。

    private static object singleton;
    
    lock (singleton)
    {
        // Some manipulations with your server
    }
    
        2
  •  1
  •   Tom Tresansky    16 年前

    这将防止99%的这类事情发生,通过确保对象总是在您使用完它们时被释放。

        3
  •  0
  •   jweber    16 年前

    VMAtm:也许你得到了一些东西,因为在网站获得越来越多的用户之后,异常显示得更多。我有一个静态类来保存使用单例方法的数据库连接。。。

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

    这种方法完全省钱吗?

    推荐文章