public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create & open a SqlConnection
            SqlDataReader reader = null;
            SqlConnection cn = new SqlConnection(connectionString);
                try
                {
                    cn.Open();
                    //call the private overload that takes an internally owned connection in place of the connection string
                    reader = ExecuteReader(cn, null, commandType, commandText, commandParameters, SqlConnectionOwnership.Internal);
                }
                catch
                {
                    //if we fail to return the SqlDatReader, we need to close the connection ourselves
                    cn.Close();
                    MyDB._Check_Net = true;
                }
            return reader;
        }cn.Open();执行这句时抛出“无效操作,连接被关闭”的异常?这是为什么?连接字符串我敢肯定是正确的

解决方案 »

  1.   

    SqlDataReader reader = null;
    这样能连上???
      

  2.   


    reader后面有返回对象给它啊,这里应该没什么问题吧
      

  3.   

    应该还是连接字符串的问题。你试试看能不能连上
     此消息通过 【CSDN论坛 Winform测试版】 回复!
      

  4.   

    解决了,谢谢!是连接字符串的问题,在server后面还加了个1433的端口号,多此一举!