2011-07-14 45 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

是的,我認爲是。當你確切地知道哪個對象導致空引用異常時,可能會更容易說出什麼是錯誤的。現在你有幾種不同的可能性,很難說這裏發生了什麼。 –