打开窗体设计器看有没有多的SqlDataReader

解决方案 »

  1.   

    在整个解决方案里搜索“SqlDataReader”
      

  2.   

    在整个解决方案里搜索你定义的SqlDataReader.
      

  3.   

    SqlDataReader.close();
    SqlConnection.close();
      

  4.   

    在整个 解决方案里面查找
    SqlDataReader
    看它的具体 实例是什么
    没有关闭的 Close()
      

  5.   

    protected SqlDataReader dr = null;//全局的private void InitPanal()
    {
        string selectSqlString = "SELECT * FROM ClassList WHERE (Parent=0) ORDER BY Parent";
        try
        {
            con = new SqlConnection(ConString);
            cmd = new SqlCommand(selectSqlString,con);
            con.Open();
            dr = cmd.ExecuteReader();
            
            while(dr.Read())
            {
                CheckBox cb = new CheckBox();
                cb.ID = dr["Id"].ToString();
                cb.Text = dr["Title"].ToString();
                this.Panel1.Controls.Add(cb);
            }
        }
        catch(Exception ex)
        {
            Response.Write(ex.ToString());
        }
        finally
        {
            dr.Close();//释放
            cmd.Dispose();
            con.Close();
        }
    }
      

  6.   

    SqlDataReader.close();
    SqlDataReader.Dispose()
      

  7.   

    SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
      

  8.   

    SqlDataReader.close();
    SqlConnection.close();
      

  9.   

    wangsaokui(无间道III(终极无间)) 
    是对的,希望楼主mm留意要优化代码就
    一般不会用到
    SqlDataReader.close();
    SqlDataReader.Dispose()
      

  10.   

    SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
    这个就好了!
      

  11.   

    SqlDataReader.close();还要关闭连接啊
    SqlConnection.close();
      

  12.   

    protected SqlDataReader dr = null;//全局的private void InitPanal()
    {
        string selectSqlString = "SELECT * FROM ClassList WHERE (Parent=0) ORDER BY Parent";
        try
        {
            con = new SqlConnection(ConString);
            cmd = new SqlCommand(selectSqlString,con);
            con.Open();
            dr = cmd.ExecuteReader();
            
            while(dr.Read())
            {
                CheckBox cb = new CheckBox();
                cb.ID = dr["Id"].ToString();
                cb.Text = dr["Title"].ToString();
                this.Panel1.Controls.Add(cb);
            }
        }
        catch(Exception ex)
        {
            Response.Write(ex.ToString());
        }
        finally
        {
            dr.Close();//释放
            cmd.Dispose();
            con.Close();
        }
    }
      

  13.   

    wangsaokui(无间道III(终极无间)) 的方法比较好
      

  14.   

    好象在哪里看到过如果用wangsaokui(无间道III(终极无间)) 的方法可能会引起联接的关闭,在程序中还是不要用吧。
      

  15.   

    用完了SqlDataReader之后,必须将其关闭,SqlConnection对象也是一样的,暂时不关闭没有问题,当过多时就会出现连接池过多等一些问题,造成程序出错。所以用过之后必须关闭连接对象和read对象
    SqlDataReader.close();
    SqlConnection.close();
      

  16.   

    添加finally块,
    /// <summary>
    /// 删除附件ID
    /// </summary>
    /// <param name="attachmentID">要删除的附件ID</param>
    public void DeleteAttachment(int attachmentID)//ICSharp_DeleteAttachment
    {
    SqlConnection conn = new SqlConnection(PortalSettings.SqlConnectionString);
    SqlCommand comm = new SqlCommand("ICSharp_DeleteAttachment",conn);
    comm.CommandType = CommandType.StoredProcedure;

    SqlParameter param = comm.Parameters.Add(new SqlParameter("@AttachmentID",SqlDbType.Int));
    comm.Parameters[0].Value = attachmentID; try
    {
    conn.Open();
    comm.ExecuteNonQuery();
    }
    catch(Exception ex)
    {
    throw new Exception("",ex);
    }
    finally
    {
    if(conn.State != ConnectionState.Closed)
    conn.Close();
    }
    }
      

  17.   

    SqlDataReader.close();
    SqlConnection.close();
    必须写这两句才可以再次打开连接
      

  18.   

    C# 可用 Using(SqlDataReader myReader ) 
    {
    //... 你的应用逻辑
    }
    用毕,会自动释放资源
      

  19.   

    SqlDataReader.close();关闭dr
    SqlDataReader.Dispose();释放
    SqlConnection.close();关闭联接