会的SqlConnection的Dispose方法干扰连接池? [英] Will SqlConnection's Dispose Method Interfere with Connection Pool?

查看:280
本文介绍了会的SqlConnection的Dispose方法干扰连接池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的理解,将净池的SqlConnection对象,其中连接字符串是一样的默认。将连接仍然汇集,如果我调用Dispose方法?这个问题是一个ASP .NET应用程序,有时使许多命中数据库在一个pageLoad的事件的环境下问。我想的连接被汇集,但想确认关闭并处置一旦数据操作的连接的完成不与连接池的.Net在处理干扰。

From my understanding, .Net will pool SqlConnection objects where the Connection String is the same by default. Will the connection still be pooled if I call the Dispose method? This question is asked under the context of an ASP .Net application that at times makes many hits to the database in a single PageLoad event. I want the connections to be pooled, but would like confirmation that Closing and Disposing of the connection once the data operation is complete does not interfere with .Net's handling of the connection pool.

推荐答案

在使用连接池,关闭的SqlConnection 只是告诉你用它做连接池。然后,池将决定是否真正关闭连接,或再使用它。

When using connection pooling, closing a SqlConnection simply tells the connection pool that you are done with it. The pool will then decide whether or not to actually close the connection, or to reuse it.

MSDN文档

如果关闭SqlConnection超出范围,它不会关闭。因此,你必须明确地关闭通过调用关闭或处置连接。关闭并处置在功能上是等价的。如果连接池值池设置为true或yes,则返回底层连接返回到连接池。另一方面,如果池被设置为假或否,到服务器的基础连接被关闭。

If the SqlConnection goes out of scope, it won't be closed. Therefore, you must explicitly close the connection by calling Close or Dispose. Close and Dispose are functionally equivalent. If the connection pooling value Pooling is set to true or yes, the underlying connection is returned back to the connection pool. On the other hand, if Pooling is set to false or no, the underlying connection to the server is closed.

这篇关于会的SqlConnection的Dispose方法干扰连接池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆