关于SqlDataReader 的关闭问题
我在过程中是用了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();
但是我发现在访问量大的时候,我的数据库连接还是满了,请问应该怎么做?
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();
但是我发现在访问量大的时候,我的数据库连接还是满了,请问应该怎么做?
...全文
相关推荐
c#中SqlHelper封装SqlDataReader的方法
主要介绍了c#中SqlHelper封装SqlDataReader的方法,涉及C#针对数据库相关操作封装与使用的技巧,需要的朋友可以参考下
在ADO.NET中使用SqlDataReader时可能发生泄漏
在ADO.NET中使用SqlDataReader时可能发生泄漏
阅读器关闭时 Read 的尝试无效。
在C#中连接数据库时,错误提示:阅读器关闭时 Read 的尝试无效。
VS2005(c#)项目调试问题解决方案集锦(一)
VS2005(c#)项目调试问题解决方案集锦(一)
SqlDataReader用法问题
主要是对数据库的连接语句。我现在想问的是如果数据库存储某一项的数据为空时(比如sdr.GetString(10)这项在数据库中的值为空时)编译会报错 怎么修改 ,实际中不可能每个人的资料都齐全。比如 有些人的还没手机


