如何在已部署的ASP.Net应用程序上跟踪错误?

时间:2011-07-14 22:24:26

标签: asp.net asp.net-mvc

VS 2008 / ASP.Net

我在Windows 2003 Server上部署了一个ASP.Net Web应用程序。由于某些原因,它会引发错误。

应用程序在我的本地计算机上运行良好。源代码或托管在我的本地计算机(Windows XP)上。

如何在已部署的ASP.Net Web应用程序上跟踪错误?

错误:

  

对象引用未设置为对象的实例。描述:一个   在执行当前Web期间发生了未处理的异常   请求。请查看堆栈跟踪以获取有关的更多信息   错误以及它在代码中的起源。

     

异常详细信息:System.NullReferenceException:不是对象引用   设置为对象的实例。

     

来源错误:

     

执行期间生成了未处理的异常   当前的网络请求。有关的来源和位置的信息   可以使用下面的异常堆栈跟踪来识别异常。

     

堆栈追踪:

[NullReferenceException: Object reference not set to an instance of an object.]
   _Default.ExportRx30ToSalisburyAccessDB() +351
   _Default.Button1_Click(Object sender, EventArgs e) +5
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

源代码:我正面临这个错误..

试         {

        Access.Application access1 = new Access.Application();

        // Open the Access database for exclusive access
        string sSalisburyAccessDB = Server.MapPath("~/App_Data/Salisbury.mdb");

        access1.OpenCurrentDatabase(sSalisburyAccessDB, true, null);

        // Drop the existing table data

        access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "drug");
        access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "patplan");
        access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "plans");
        access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "price");
        access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "rx");
        access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "patient");
        access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "plntrak");

        // Run the saved import
        access1.DoCmd.RunSavedImportExport("SalisburyODBC");

        // Close the database
        access1.CloseCurrentDatabase();

        // Quit MS Access
        access1.Quit(Access.AcQuitOption.acQuitSaveAll);

        Response.Write("successful");

    }
    catch (Exception ex)
    {
        Response.Write(ex.InnerException.Message);
    }

4 个答案:

答案 0 :(得分:1)

尝试在调试模式下部署应用程序,该模式应该为您提供发生错误的特定行号和代码文件。只需将其放在web.config文件中:

即可
<configuration>
  <system.web>
    <compilation debug="true">
  </system.web>
</configuration>

但是,一般情况下,您不希望deploy to final production in debug mode。相反,在应用程序中使用try...catch块和良好状态/异常日志记录来跟踪问题。

答案 1 :(得分:1)

尝试在IIS Express而不是Cassini(内置的Visual Studio开发Web服务器)中运行您的应用。它们的行为方式不同,您可能会更好地在开发环境中重新创建问题。 IIS Express就像真正的IIS一样运行,因此在部署应用程序时可以减少意外情况。

答案 2 :(得分:1)

查找此类错误发生位置的最简单方法是将方法拆分为每个方法只做一件事。例如,不是添加说// Run the saved import的注释,而是创建RunTheSavedImport()的方法,您将更容易检测到错误直接从堆栈跟踪发生在代码的哪个部分。

我可以看到,如果您提供的代码是完整的ExportRx30ToSalisburyAccessDB方法,则此错误的最可能原因是DoCmd,AcQuitOption或某种原因的AcObjectType为空。由于堆栈没有进入应用程序,因此只能由此方法中的对象引起。

答案 3 :(得分:-1)

[ObjectDisposedException:无法访问已关闭的资源集。] System.Resources.RuntimeResourceSet.GetObject(String key,Boolean ignoreCase,Boolean isString)+1657 System.Resources.RuntimeResourceSet.GetString(String key,Boolean ignoreCase)+12 System .Resources.ResourceManager.GetString(String name,CultureInfo culture)+78 SourceCode.Workspace.OOBReports.ReportList.CreateChildControls()+ 347 System.Web.UI.Control.EnsureChildControls()+ 146 System.Web.UI.Control.PreRenderRecursiveInternal ()+61 System.Web.UI.Control.PreRenderRecursiveInternal()+ 224 System.Web.UI.Control.PreRenderRecursiveInternal()+ 224 System.Web.UI.Control.PreRenderRecursiveInternal()+ 224 System.Web.UI.Control .PreRenderRecursiveInternal()+ 224 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+3394

只需重置您的IIS服务器。