关于SqlDataReader 的关闭问题

celeries celeries 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在过程中是用了CommandBehavior.CloseConnection,具体代码如下
public SqlDataReader GetUserplace(string Value)
{
string conn, sql;
conn = "server=MSSQL;uid=caexpo;pwd=caexpo;database=Question";
sql = Value;
SqlConnection connection = new SqlConnection(conn);
connection.Open();
SqlCommand objCommand = new SqlCommand(sql,connection);

SqlDataReader objReader ;
objReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection);
return objReader;
}

在页面上,我用SqlDataReader objReader = GetUserplace("xxx")进行调用,在调用完成后,我及时的关闭了在页面上创建的objReader ,关闭方法如下:objReader.close();

但是我发现在访问量大的时候,我的数据库连接还是满了,请问应该怎么做?
...全文
评论 18
收藏 已收藏
分享
返回顶部
celeries
C# 111,129 成员 642,539 内容