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

アプリをCassini(ビルトインのVisual Studio開発Webサーバー)ではなくIIS Expressで実行してみてください。それらは異なった振る舞いをしており、開発環境で問題を再現することができます。 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ブロックを使用しています。 – goofyui

+0

@Chok - 私は確かにあなたがdebug = "true"のプロダクションウェブサイトを扱っていないことを願っています。 – Tim

1

このようなエラーが発生する場所を見つける最も簡単な方法は、メソッドごとに分割してメソッドごとに1つだけ行うことです。たとえば、// Run the saved importというコメントを追加する代わりに、RunTheSavedImport()のメソッドを作成すると、スタックのトレースから直接エラーが発生したコードの部分を簡単に検出できるようになります。

あなたが提供したコードが完全なExportRx30ToSalisburyAccessDBメソッドである場合、何らかの理由でDoCmd、AcQuitOptionまたはAcObjectTypeのいずれかがnullである可能性が最も高い原因です。スタックはアプリケーションに入らないので、このメソッド内のオブジェクトによってのみ引き起こされる可能性があります。

+0

あなたは正しいかもしれません、方法を分割することができます.. !! – goofyui

+1

はい私はそう思います。ヌル参照例外の原因となっているオブジェクトを正確に知っていると、何が間違っているのかを言うのがずっと簡単になります。今ここには本当に何が起こっているのかが難しいいくつかの可能性があります。 –