none
Object reference not set to an instance of an object异常如何解决 RRS feed

  • 问题

  • Server Error in '/' Application.

    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.]
      System.Data.OleDb.OleDbConnection.ValidateTransaction(OleDbTransaction transaction, String method) +18
      System.Data.OleDb.OleDbCommand.ValidateConnectionAndTransaction(String method) +40
      System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +56
      System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +116
      System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +4
      System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130
      System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
      System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +94
      DataAccess.GetDataSet(String sql) in e:\CTC网站\Flowers\Flowerweb\App_Code\DataAccess.cs:57
    
    [Exception: Object reference not set to an instance of an object.]
      DataAccess.GetDataSet(String sql) in e:\CTC网站\Flowers\Flowerweb\App_Code\DataAccess.cs:62
      _Default.Page_Load(Object sender, EventArgs e) in e:\CTC网站\Flowers\Flowerweb\Default.aspx.cs:21
      System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
      System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
      System.Web.UI.Control.OnLoad(EventArgs e) +99
      System.Web.UI.Control.LoadRecursive() +50
      System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

    我弄的网站在多人同时打开页面的时候会出现这个异常,提示我数据访问层出现异常。我认为是多线程的问题,但是没有发现代码的问题。

    有经验的朋友帮忙看看。

    2010年9月28日 23:28

答案

全部回复

  • stack trace below.

    stack trace 呢?

    你发在这个论坛,是因为stack trace在System.Data里面?



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2010年9月29日 5:54
    版主
  • 我把stack trace 贴上了,您看看吧,谢谢
    2010年9月29日 12:30
  • DataAccess.GetDataSet估计有静态的成员。而且不是线程安全的。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    • 已标记为答案 jalongod 2010年10月11日 12:18
    2010年9月29日 14:22
    版主
  • Server Error in '/' Application.

    No data exists for the row/column.

    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.InvalidOperationException: No data exists for the row/column.

    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: 

    [InvalidOperationException: No data exists for the row/column.]
      System.Data.OleDb.OleDbDataReader.GetFieldType(Int32 index) +1032875
      System.Data.ProviderBase.CommonLanguageSubsetDataReader.GetFieldType(Int32 ordinal) +13
      System.Data.ProviderBase.SchemaMapping.SetupSchemaWithoutKeyInfo(MissingMappingAction mappingAction, MissingSchemaAction schemaAction, Boolean gettingData, DataColumn parentChapterColumn, Object chapterValue) +1406
      System.Data.ProviderBase.SchemaMapping..ctor(DataAdapter adapter, DataSet dataset, DataTable datatable, DataReaderContainer dataReader, Boolean keyInfo, SchemaType schemaType, String sourceTableName, Boolean gettingData, DataColumn parentChapterColumn, Object parentChapterValue) +285
      System.Data.Common.DataAdapter.FillMappingInternal(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 schemaCount, DataColumn parentChapterColumn, Object parentChapterValue) +91
      System.Data.Common.DataAdapter.FillMapping(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 schemaCount, DataColumn parentChapterColumn, Object parentChapterValue) +77
      System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) +85
      System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) +353
      System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +164
      System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
      System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +94
      DataAccess.GetDataSet(String sql) in e:\CTC网站\Flowers\Flowerweb\App_Code\DataAccess.cs:57
    
    [Exception: No data exists for the row/column.]
      DataAccess.GetDataSet(String sql) in e:\CTC网站\Flowers\Flowerweb\App_Code\DataAccess.cs:62
      _Default.Page_Load(Object sender, EventArgs e) in e:\CTC网站\Flowers\Flowerweb\Default.aspx.cs:21
      System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
      System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
      System.Web.UI.Control.OnLoad(EventArgs e) +99
      System.Web.UI.Control.LoadRecursive() +50
      System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

    我弄的网站在多人同时打开页面的时候会出现这个异常,提示我数据访问层出现异常。我认为是多线程的问题,但是没有发现代码的问题。

    有经验的朋友帮忙看看。

    2010年9月29日 23:26
  • 是你数据读取的问题,

    解决办法:http://blog.csdn.net/longronglin/archive/2007/05/21/1619740.aspx


    http://blog.csdn.net/zx13525079024
    2010年9月30日 1:11
  • Hi ni hao,

    Try setting a breakpoint in your code in VS to see where the null object is. Maybe you forgot to instantiate one of the objects and the object you are trying to bind is missing...this can happen when it is inside a masterpage, etc...Post your codes then others can help you better.

     

     

    2010年10月4日 20:32