2011-07-14 37 views
0

VS 2008/ASP.Net如何跟踪部署的ASP.Net应用程序的错误?

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

应用程序在我的本地计算机上运行良好。无论是从源代码还是托管在本地机器上(Windows XP)。

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

错误:

Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[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); 
    } 
+1

您是否尝试过在调试模式下部署应用程序? – mellamokb

+0

不,我应该怎么做?我部署在一个正常的过程! – goofyui

+0

请参阅下面的答案。 – mellamokb

回答

1

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

1

尝试部署在调试模式下,应用程序,应该给你一个错误发生的特定行号和代码文件。只要把这个在您的web.config文件:

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

然而,在一般情况下,你不想deploy to final production in debug mode。相反,在您的应用程序中使用try...catch块和良好状态/异常记录来追踪问题。

+0

+1未配置调试模式以生产和使用try ... catch以及良好的日志记录。 – Tim

+0

默认情况下,debug =“true”!我正在使用Try Catch Block – goofyui

+0

@Chok - 我当然希望你没有处理debug =“true”的生产网站。 – Tim

1

找到发生这种错误的最简单方法是将您的方法拆分为每种方法只做一件事。例如,不是添加一个说// Run the saved import的注释,而是使用RunTheSavedImport()方法来创建一个方法,并且您可以更容易地从堆栈跟踪中直接检测错误发生在哪部分代码中。

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

+0

你可能是对的,让我分裂的方法..! – goofyui

+1

是的,我认为是。当你确切地知道哪个对象导致空引用异常时,可能会更容易说出什么是错误的。现在你有几种不同的可能性,很难说这里发生了什么。 –