ITPUB??ì3
ITPUB论坛 » Web开发 » ASP.NET与AJAX » 请教一下非一般的未将对象引用设置到对象的实例的错误,急!!


标题: 请教一下非一般的未将对象引用设置到对象的实例的错误,急!!
离线 tnttmd
初级会员


精华贴数 0
个人空间 0
技术积分 109 (15339)
社区积分 0 (849251)
注册日期 2006-4-8
论坛徽章:0
      
      

发表于 2008-4-28 21:06 
请教一下非一般的未将对象引用设置到对象的实例的错误,急!!

网站是当连着刷新或者打开一定次数后就出现下面的错误,但过段时间后又正常了。请问是什么原因啊?非常感谢


未将对象引用设置到对象的实例
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 23:         ForNotice.Text += "<tr>";
行 24:         tDr = common.GetTopRec("[Notices]", 5, "[N_ID]";
行 25:         while (tDr.Read())
行 26:         {
行 27:             ForNotice.Text += "<td align='right' width='10%'><img src='images/pic2.jpg'/></td><td align='left'><a href='ShowNotices.aspx?ID=" + tDr["N_ID"].ToString() + "' style='color: #d6d6cc; font-size:11pt' target='_blank'>" + tDr["N_Title"].ToString() + "</a>    <font color='#d6d6cc' size='2pt'>" + tDr["N_Date"].ToString() + "</font><br></td></tr>";


源文件: e:webmanagementonlineIndex.aspx.cs    行: 25

堆栈跟踪:


[NullReferenceException: 未将对象引用设置到对象的实例。]
   Index.Page_Load(Object sender, EventArgs e) in e:webmanagementonlineIndex.aspx.cs:25
   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


代码如下:

<add name="Conn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:DoingonlineApp_DataEBDataBase.mdb"/>

    public OleDbConnection Con = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
    public OleDbCommand Cmd = null;
    private static string FileName = "H:\Doing\online\Logs\Logs.txt";
    public string ErrorInfo = "";

    public void Open()
    {
        if (Con.State == ConnectionState.Closed)
        {
            try
            {
                Con.Open();
            }
            catch (Exception ex)
            {
                SqlHelper.CreatErrorMessage(ex.Message);
            }
            finally
            {
            }
        }
    }

    public void Close()
    {
        if (Con != null)
        {
            if (Con.State == ConnectionState.Open)
            {
                Con.Close();
            }
        }
    }

    public void Action(string CmdLine,out int nResult)
    {
        nResult = -1;
        Cmd = new OleDbCommand(CmdLine, Con);
        Open();
        try
        {
            CreatErrorMessage(CmdLine);
            nResult = Cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            ErrorInfo = ex.Message;
            CreatErrorMessage(ErrorInfo);
        }
        finally
        {
            Close();
        }
    }

显示时:
Common common = new Common();
        OleDbDataReader tDr = null;
        ForNotice.Text += "<font color='#d6d6cc'><div align=center>最新通知</div></font>";
        ForNotice.Text += "<table width='100%' border='0'>";
        ForNotice.Text += "<tr>";
        tDr = common.GetTopRec("[Notices]", 5, "[N_ID]");
        while (tDr.Read())
        {
            ForNotice.Text += "<td align='right' width='10%'><img src='images/pic2.jpg'/></td><td align='left'><a href='ShowNotices.aspx?ID=" + tDr["N_ID"].ToString() + "' style='color: #d6d6cc; font-size:11pt' target='_blank'>" + tDr["N_Title"].ToString() + "</a>&nbsp;&nbsp;&nbsp;&nbsp;<font color='#d6d6cc' size='2pt'>" + tDr["N_Date"].ToString() + "</font><br></td></tr>";
        }
        ForNotice.Text += "</table>";

[ 本帖最后由 tnttmd 于 2008-4-28 22:12 编辑 ]


__________________
只看该作者    顶部
离线 zengshaojie
执着的青蛙


精华贴数 0
个人空间 0
技术积分 956 (1923)
社区积分 1547 (687)
注册日期 2006-11-14
论坛徽章:17
授权会员2008北京奥运纪念徽章:拳击2008北京奥运纪念徽章:棒球生肖徽章2007版:蛇生肖徽章2007版:羊生肖徽章2007版:牛
2008北京奥运纪念徽章:垒球生肖徽章2007版:猪2008年新春纪念徽章生肖徽章2007版:鸡生肖徽章2007版:虎生肖徽章2007版:兔

发表于 2008-4-28 21:20 
好像是多次打开关闭数据库出问题了


__________________
我是灌灌帮青蛙
--------------------------------------------
放弃执着过却得不到结果的执着!
-------青蛙的感悟

-------------------
ps:ziyi0808 是我师父!
---------------------------------------------
相濡与沫,不如相忘于江湖!
---------------------------------------------

卖魔镜咯!http://shop.paipai.com/171707424?RDTAG=199.1.2&PTAG=40005.7.3大家看看啊!
只看该作者    顶部
离线 tnttmd
初级会员


精华贴数 0
个人空间 0
技术积分 109 (15339)
社区积分 0 (849251)
注册日期 2006-4-8
论坛徽章:0
      
      

发表于 2008-4-28 21:31 
那请问我该怎么改啊?谢谢


__________________
只看该作者    顶部
离线 mosticy
中级会员


精华贴数 0
个人空间 0
技术积分 2380 (652)
社区积分 2182 (542)
注册日期 2007-10-9
论坛徽章:2
      
      

发表于 2008-4-29 11:44 
IIS 扛不住的时候,也会出现上面的错误。
当应用程序的用户访问量超过它能承受的范围之后,就会出错。
改善你的程序,使用缓存,尽量减少与数据库交互的次数。


__________________
(止步海阔天空.)
只看该作者    顶部
离线 smthgdin
老会员



精华贴数 0
个人空间 0
技术积分 1319 (1284)
社区积分 1 (34680)
注册日期 2004-5-13
论坛徽章:2
ITPUB元老开发板块每日发贴之星    
      

发表于 2008-4-30 18:02 
比较支持4楼说法,connection还在连接池中,打开关闭开销足够小。


__________________
www.kooboy.net
只看该作者    顶部
离线 tnttmd
初级会员


精华贴数 0
个人空间 0
技术积分 109 (15339)
社区积分 0 (849251)
注册日期 2006-4-8
论坛徽章:0
      
      

发表于 2008-4-30 20:30 
现在更夸张了,多刷几次后就服务器死机。。。。


__________________
只看该作者    顶部
离线 tnttmd
初级会员


精华贴数 0
个人空间 0
技术积分 109 (15339)
社区积分 0 (849251)
注册日期 2006-4-8
论坛徽章:0
      
      

发表于 2008-4-30 22:09 
问题解决,public OleDbConnection Con = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
改为public static OleDbConnection Con = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);

然后在每次读取后加上sqlhelper.con.close();

请问有谁知道原因吗?


__________________
只看该作者    顶部
离线 zengshaojie
执着的青蛙


精华贴数 0
个人空间 0
技术积分 956 (1923)
社区积分 1547 (687)
注册日期 2006-11-14
论坛徽章:17
授权会员2008北京奥运纪念徽章:拳击2008北京奥运纪念徽章:棒球生肖徽章2007版:蛇生肖徽章2007版:羊生肖徽章2007版:牛
2008北京奥运纪念徽章:垒球生肖徽章2007版:猪2008年新春纪念徽章生肖徽章2007版:鸡生肖徽章2007版:虎生肖徽章2007版:兔

发表于 2008-4-30 22:57 
4楼和 5楼不是告诉你原因了吗?


__________________
我是灌灌帮青蛙
--------------------------------------------
放弃执着过却得不到结果的执着!
-------青蛙的感悟

-------------------
ps:ziyi0808 是我师父!
---------------------------------------------
相濡与沫,不如相忘于江湖!
---------------------------------------------

卖魔镜咯!http://shop.paipai.com/171707424?RDTAG=199.1.2&PTAG=40005.7.3大家看看啊!
只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问