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();执行这句时抛出“无效操作,连接被关闭”的异常?这是为什么?连接字符串我敢肯定是正确的
这样能连上???
reader后面有返回对象给它啊,这里应该没什么问题吧
此消息通过 【CSDN论坛 Winform测试版】 回复!