Sorry! 是我搞错了 It is recommended that you always close the Connection when you are finished using it in order for the connection to be returned to the pool. This can be done using either the Close or Dispose methods of the Connection object. Connections that are not explicitly closed might not be added or returned to the pool.
执行Close()不释放数据库连接池的资源,而是把连接放回连接池中待用;Dispose则会把这个连接彻底销毁掉,不会再放入连接池。如果所有的连接都被Dispose的话,每次使用数据库都必须重新创建连接,这样很耗费资源。因此不要用Dispose,.NET会维护连接池,连接Open的时候从连接池中取出一个没有使用的连接,用完以后Close()的时候再放回连接池,实际上没有创建新的连接,从而提高了性能。
因此为了性能,为了使用连接池,不可以dispose,但必须close().NET中所有创建的对象有垃圾收集器进行管理,不需要释放或dispose
{
if (disposing)
{
switch (this._objectState)
{
case ConnectionState.Open:
{
this.Close();
break;
}
}
this._constr = null;
}
base.Dispose(disposing);
}我也查看了 close,以及base.Dispose。没有对连接池的额外操作。
It is recommended that you always close the Connection when you are finished using it in order for the connection to be returned to the pool. This can be done using either the Close or Dispose methods of the Connection object. Connections that are not explicitly closed might not be added or returned to the pool.
================这这一句执行的是什么呢?================================
re:为了释放数据库连接池的资源,仅需要执行close,执行dispose是多余的。
执行Close()不释放数据库连接池的资源,而是把连接放回连接池中待用;Dispose则会把这个连接彻底销毁掉,不会再放入连接池。如果所有的连接都被Dispose的话,每次使用数据库都必须重新创建连接,这样很耗费资源。因此不要用Dispose,.NET会维护连接池,连接Open的时候从连接池中取出一个没有使用的连接,用完以后Close()的时候再放回连接池,实际上没有创建新的连接,从而提高了性能。
因此为了性能,为了使用连接池,不可以dispose,但必须close().NET中所有创建的对象有垃圾收集器进行管理,不需要释放或dispose=====================我赞同这种说法。