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

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

问题描述

从我的理解,.Net将池 SqlConnection 对象的连接字符串是相同的默认情况下。如果我调用Dispose方法,连接是否仍然是池?

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?

这个问题是在ASP.NET应用程序的上下文中提出的,它有时在单个 PageLoad 事件。我想要连接池,但希望确认关闭和处理连接一旦数据操作完成不会干扰.NET的连接池的处理。

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超出范围,它不会被关闭。因此,必须通过调用Close或Dispose显式关闭连接。关闭和处置功能相同。如果连接池值Pooling设置为true或yes,则底层连接将返回到连接池。另一方面,如果Pooling设置为false或否,则关闭与服务器的底层连接。

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天全站免登陆