总结,除了dataReader其他基本不用close,但是SqlDateReader dr = cmd.ExecuteReader(commandBehavious.ConnectionClosed)也只是为了关闭reader后关闭connection用的。归根结底还是为了关闭connection罢了。如果连接多了,只有gc会去回收而不是连接池。gc又是不定时不马上的。所以要加using(connection) http://bbs.csdn.net/top...
close掉的connection可以重新open,dispose的不行,因为connectionstring清空了,会抛出InvalidOperationException提示The ConnectionString property has not been initialized,但此时sqlconnection对象还在。 如果dispose后给connectionString重新赋值,则不会报错。 由此得出的结论是不管是dispose还是close都不会销毁对象,即不会释放内...
SqlConnection对象的()方法用于关闭数据库连接。A.Opener()B.Closer()C.Open()D.Close()搜索 题目 SqlConnection对象的()方法用于关闭数据库连接。 A.Opener()B.Closer()C.Open()D.Close() 答案 D 解析收藏 反馈 分享
不能。最好每次close,而且最好的方式是using语句(C#)。因为数据库连接是非托管资源,如果你不关闭有可能影响其他人使用,或者造成数据库不稳定。另,数据库本身有连接池一类的技术来实现较高性能,所以不需要你再在客户端做什么处理。
import javax.sql.DataSource; //这是同过增强Connection类[重写了close的方法]实现的从连接池取出连接并放回连接 public class JdbcPool implements DataSource { // 创建连接池,用的是LinkList, private static LinkedList<Connection> connections = new LinkedList<Connection>(); ...
立即释放此 SQLServerConnection 对象的数据库和 JDBC 资源,而非等待它们自动释放。 语法 复制 public void close() 异常 SQLServerException 备注 此close 方法由 java.sql.Connection 接口中的 close 方法指定。 在事务中间调用 close 方法将回滚该事务。 请参阅 参考 SQLServerConnection 类 概念 ISQLServerConnect...
多此一举.使用using语句块与使用close或Dispose是等效的.
下面的示例创建一个 SqlCeConnection 并打开它,执行一个查询,然后关闭此连接。C# 复制 SqlCeConnection conn = null; try { conn = new SqlCeConnection("Data Source = MyDatabase.sdf; Password ='<pwd>'"); conn.Open(); SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO ...
不关闭查询会持续占用服务器资源,会话多了服务器会非常卡,而且如果查询中有临时表的话,不关闭会话临时表会重复的
e.g:If in one class I call select method( which will make a connection and I keep it in variable "con") and during selection from DB, another class calls method delete (which will make another connection named "con" ). please mention that now we have 2 connection both named "con" ...