CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

c#.net奇怪问题。大虾们帮帮忙

楼主gavinluo()2005-08-03 23:04:01 在 .NET技术 / ASP.NET 提问

为什么我运行程序时会出现这个错误?其他机子正常。而且对数据库进行写或更改操作时提示dataset以打开,需要关闭???请大家帮忙!  
   
   
  错误代码  
   
  There   is   already   an   open   DataReader   associated   with   this   Connection   which   must   be   closed   first.    
  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:   There   is   already   an   open   DataReader   associated   with   this   Connection   which   must   be   closed   first.  
   
  Source   Error:    
   
  The   source   code   that   generated   this   unhandled   exception   can   only   be   shown   when   compiled   in   debug   mode.   To   enable   this,   please   follow   one   of   the   below   steps,   then   request   the   URL:  
   
  1.   Add   a   "Debug=true"   directive   at   the   top   of   the   file   that   generated   the   error.   Example:  
   
      <%@   Page   Language="C#"   Debug="true"   %>  
   
  or:  
   
  2)   Add   the   following   section   to   the   configuration   file   of   your   application:  
   
  <configuration>  
        <system.web>  
                <compilation   debug="true"/>  
        </system.web>  
  </configuration>  
   
  Note   that   this   second   technique   will   cause   all   files   within   a   given   application   to   be   compiled   in   debug   mode.   The   first   technique   will   cause   only   that   particular   file   to   be   compiled   in   debug   mode.  
   
  Important:   Running   applications   in   debug   mode   does   incur   a   memory/performance   overhead.   You   should   make   sure   that   an   application   has   debugging   disabled   before   deploying   into   production   scenario.      
   
  Stack   Trace:    
   
   
  [InvalidOperationException:   There   is   already   an   open   DataReader   associated   with   this   Connection   which   must   be   closed   first.]  
        System.Data.OleDb.OleDbConnection.SetStateExecuting(OleDbCommand   attempt,   String   method,   Boolean   flag)   +103  
        System.Data.OleDb.OleDbCommand.ValidateConnectionAndTransaction(String   method,   Int32&   localState)   +103  
        System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior   behavior,   String   method)   +61  
        System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior   behavior)   +69  
        System.Data.OleDb.OleDbCommand.ExecuteReader()   +7  
        ASP.index_aspx.Page_Load(Object   Src,   EventArgs   E)   +170  
        System.Web.UI.Control.OnLoad(EventArgs   e)   +67  
        System.Web.UI.Control.LoadRecursive()   +35  
        System.Web.UI.Page.ProcessRequestMain()   +731  
   
     
  问题点数:20、回复次数:4Top

1 楼birdxxxx(爱上老鼠的猫)回复于 2005-08-03 23:10:07 得分 0

错误提示为你使用的时候Connection对象已经关联了一个DataReader,即有一个连接的Reader没有被关闭。你查一下你的代码吧Top

2 楼gavinluo()回复于 2005-08-03 23:13:52 得分 0

可是在其他机子上就没事,代码如下:  
  <%@   Page   Language="C#"   ContentType="text/html"   ResponseEncoding="gb2312"   %>  
  <%@   Import   Namespace="System"   %>  
  <%@   Import   Namespace="System.Data"   %>  
  <%@   Import   Namespace="System.Data.OleDb"   %>  
   
  <script   runat="server">  
  protected   void   Page_Load(Object   Src,   EventArgs   E)  
  {  
    string   strConnection="Provider=Microsoft.Jet.OleDb.4.0;";  
    strConnection+="Data   Source=";  
    strConnection+=MapPath("data\\data.mdb");  
    OleDbConnection   objConnection=new   OleDbConnection(strConnection);  
    objConnection.Open();  
   
   
  for(int   i=0;i<=2;i++)  
  {  
   
  int   tp=i+1;  
  //   OleDbCommand   objCommand   =   new   OleDbCommand("select   *,wen   len(title)>10   then(substring(title,0,10)+'...')   else   title   end   as   title   from   '文字'   where   位置='index"+   tp   +"'"   ,   objConnection);  
    OleDbCommand   objCommand   =   new   OleDbCommand("select   *   from   文字   where   位置='index"+   tp   +"'"   ,   objConnection);  
   
    OleDbDataReader   objDataReader=objCommand.ExecuteReader();  
    if(objDataReader.Read())  
    {  
   
        string   lcID="lable"+i*3+1;  
        Control   loCtrl=this.FindControl(lcID);  
        if   (loCtrl!=null&&loCtrl   is   Label)  
        {  
            //string   myString   =   Convert.ToString(objDataReader["标题"]);  
             
            ((Label)loCtrl).Text=Convert.ToString(objDataReader["标题"]);  
        }  
         
        lcID="lable"+i*3+2;  
        loCtrl=this.FindControl(lcID);  
        if   (loCtrl!=null&&loCtrl   is   Label)  
        {  
            //   string   myString   =   Convert.ToString(objDataReader["内容"]);  
            ((Label)loCtrl).Text=Convert.ToString(objDataReader["内容"]);  
        }  
      }  
   
    }  
   
    for(int   i=1;i<=3;i++)  
    {  
        OleDbCommand   objCommand   =   new   OleDbCommand("select   *   from   图片   where   位置='index"+   i   +"'"   ,   objConnection);  
      OleDbDataReader   objDataReader=objCommand.ExecuteReader();  
    if(objDataReader.Read())  
    {  
      string   lcID="image"+i;  
      Control   loCtrl=this.FindControl(lcID);  
        if   (loCtrl!=null&&loCtrl   is   Label)  
        {  
            ((Image)loCtrl).ImageUrl=Convert.ToString(objDataReader["地址"]);  
        }  
    }  
   
   
    }  
   
    objConnection.Close();  
  }Top

3 楼birdxxxx(爱上老鼠的猫)回复于 2005-08-04 00:12:36 得分 20

你创建了两次objDataReader对象,你最好把它们提到For循环的外面,只创建一次,然后使用。Top

4 楼jack1026(杭杭)回复于 2005-08-04 00:39:52 得分 0

你objDataReader对象创建了多少次啊.只要在循环的最外面一次就够了啊.Top

相关问题

  • 绝对不是搞笑! C#.NET 、C++BUILDER之一奇怪现象。请假专家!
  • 绝对不是搞笑! C#.NET 、C++BUILDER之一奇怪现象。请教专家!
  • C#.net中很奇怪的问题,求助,在线等!!!
  • c++的奇怪警告
  • c++的奇怪问题
  • 奇怪的问题:关于.net自带例子“创建分布式应用程序”(c#)
  • C#.NET中遇到的奇怪的问题,困扰我很久了,快救我啊!
  • C#.net 关于Excel打印问题,非常奇怪的现象,望高手指点
  • 奇怪的 C 问题(SCO UNIX下)
  • 一个奇怪的C语言语法???

关键词

  • 代码
  • source
  • application
  • loctrl
  • objdatareader
  • oledbcommand
  • lcid
  • strconnection
  • objconnection
  • oledb

得分解答快速导航

  • 帖主:gavinluo
  • birdxxxx

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo