一个奇怪的错误。
在本机测试是没有错误的。上传到服务器也没有错误,但是访问的人一多,就报错(没有绑定到对象)。
至今没找到错误原因。
用的是三层架构,用存储过程。
其中的一个错误页面提示是这样的,哪位达人能否给个解决思路?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.]
   DAL.NewsSQL.Get_NewsNum(Int32 nClassID) in E:\lwy\lwy1012\DAL\NewsSQL.cs:424
   BLL.NewsSystem.Get_NewsNum(Int32 nClassID) in E:\lwy\lwy1012\BLL\NewsSystem.cs:117
   LinWu.News_More.Page_Load(Object sender, EventArgs e) +195
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436 

解决方案 »

  1.   

    Get_NewsNum---应该是这个方法执行的时候有问题
      

  2.   

    应该是对象没有实例化,缺少new
      

  3.   

    出现错误的代码在这儿。不知道有何错误,请高手指教public int Get_NewsNum()
            {
                SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper();
                SqlParameter[] ParamList ={ 
                    sqlHelper.CreateInParam("@startIndex",SqlDbType.Int,4,1),
                    sqlHelper.CreateInParam("@endIndex",SqlDbType.Int,4,1),
                    sqlHelper.CreateInParam("@docount",SqlDbType.Bit,1,1)
                };
                SqlDataReader rec = null;
                try
                {
                    sqlHelper.RunProc("Get_News", ParamList, out rec);
                }
                catch (Exception ex)
                {
                    SystemError.CreateErrorLog(ex.Message);
                    throw new Exception(ex.Message, ex);
                }
                int Num = 0;
                while (rec.Read())
                {
                    Num = Int32.Parse(rec["Counts"].ToString());
                }
                sqlHelper.Close();
                return Num;
            }/// <summary>
    /// 执行存储过程
    /// </summary>
    /// <param name="procName">存储过程的名称</param>
    /// <param name="prams">存储过程所需参数</param>
    /// <param name="dataSet">返回DataReader对象</param>
    public void RunProc(string procName, SqlParameter[] prams, out SqlDataReader dataReader) 
    {
    ///创建Command
    SqlCommand cmd = CreateProcCommand(procName, prams);

    try
    {
    ///读取数据
    dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    }
    catch(Exception ex)
    {
    dataReader = null;
    ///记录错误日志
    SystemError.CreateErrorLog(ex.Message);
                    Close();
    }    
    }
      

  4.   

    会不会有些对象没有创建成功就使用了?建议对new创建的对象判断一下是否成功,不成功的不许使用。