关闭Connection前检查一下有没有和它关联的DataReader没关闭,如何得到和它关联的DataReader?
解决方案 »
- asp.net 问题, to come in
- ASP.NET网站ACCESS 不能访问问题 在线等
- Asp.net里会员卡的有效期怎么实现?系统可以自动判断是否到了过期时间的,高手来解答!!!
- 动态实现GridView中删除、修改操作权限
- 使用frameset时如何设置页面大小
- [求助]无法创建抽象类或接口“System.Collections.Generic.IList<Test>”的实例
- 磁盘上已经存在名为"news"的文件或文件夹,请另选一个?????????
- 非常急
- 在线等候:一个小问题,望请多多帮助小弟,数据库insert时出错!
- 在ASP.NET下如何实现VBSCRIPT中的SetTimeOut()函数?
- 请问 自定义控件中如何写font的各类属性?
- 问几个小问题,来抢分帮忙吧,(50分)晚了别怪我!!关于IIS.好的话会加分
OleDbDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection);
关闭dr就自动关闭相应的connection
To vrace(干什么呢?在写程序!) ,我自己写了个类苦,实现数据库的操作,调用时都会保存Reader,使用完后把它关闭。但我担心有时会忘记关闭Reader,所以我想在这个类库里提供个检查 的方法,根据Connection得到和它关联的DataReader,检查是否关闭
http://community.csdn.net/Expert/TopicView.asp?id=3877118
using(SqlDataReader dr = UDBClass.DataReader("select * from [tableName]")){}
//通过using 来自动关闭dr
关闭dr就自动关闭相应的connection第二种:
在.net中操作sql server如何取得sql server的错误代码和信息?SqlConnection sqlConn = null;
SqlCommand sqlCommand = null;
try
{
sqlConn = new SqlConnection(@"server=(local);database=northwind;integrated security=sspi");
sqlCommand = new SqlCommand("select * from customer", sqlConn);
sqlConn.Open();
SqlDataReader dr = sqlCommand.ExecuteReader();
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
if (sqlConn != null)
{
if (sqlConn.State != ConnectionState.Closed)
sqlConn.Close();
sqlConn.Dispose();
}
}第三种:
SqlDataReader的关闭
using(SqlDataReader dr = UDBClass.DataReader("select * from [tableName]")){}