这个参数是关闭Connection连接嘛?
但是我测试过Connection通过这语句后还是打开的.
这个参数到底是用来关闭什么的?我测过不是关闭Connection对象的

解决方案 »

  1.   

    如果关闭关联的 DataReader 对象,则关联的 Connection 对象也将关闭。 
    你应该关闭datareader后测试
      

  2.   

    CloseConnection: When the command is done executing, both the DataReader and the connection are closed.不知道楼主是怎么测试的。
    举个例子。System.Collections.ArrayList al = new System.Collections.ArrayList();using (OracleConnection conn = new OracleConnection())
    {
        conn.ConnectionString = "Data Source=**;User ID=**;Password=**";    OracleCommand cmd = new OracleCommand();
        cmd.CommandText = "select * from TABLE where ***";
        cmd.Connection = conn;    conn.Open();    OracleDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);    if (dr.HasRows)
        {
              foreach (System.Data.Common.DbDataRecord ddr in dr)
              {
                   al.Add(ddr);
              }
         }
         MessageBox.Show(conn.State.ToString()); //这里输出Closed,说明连接已经关闭
    } // 自动调用conn.Dispose()。
    dataGridView1.DataSource = al;楼主能不能把你的测试代码贴出来?