连接数据库为什么抛出异常

liusahara liusahara 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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();执行这句时抛出“无效操作,连接被关闭”的异常?这是为什么?连接字符串我敢肯定是正确的
...全文
评论 8
收藏 已收藏
分享
返回顶部
liusahara
C# 111,129 成员 642,539 内容