.net - SqlConnection的Dispose方法会干扰连接池吗?

标签 .net asp.net database vb.net connection-pooling

根据我的理解,默认情况下,.Net 将合并连接字符串相同的 SqlConnection 对象。如果我调用 Dispose 方法,连接是否仍会被合并?

这个问题是在 ASP.NET 应用程序的上下文中提出的,该应用程序有时会在单个 PageLoad 事件中多次点击数据库。我希望将连接放入池中,但希望确认在数据操作完成后关闭和处理连接不会干扰 .NET 对连接池的处理。

最佳答案

使用连接池时,关闭 SqlConnection 只是告诉连接池您已完成它。然后池将决定是否实际关闭连接,或重新使用它。

来自MSDN docs :

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.

关于.net - SqlConnection的Dispose方法会干扰连接池吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6765733/

相关文章:

c# - Debug.Assert 和 Debug.Fail 是否应该自由使用,是否应该留在生产代码中?

c# - HtmlGenericControl 和 id

c# - 如何在富文本框的文本字符串中添加 rtf 格式?

c#如何在现有对象上动态调用方法

javascript - 如何从 VB scdript 中的 url 中删除属性

mysql - 防止 super 管理员/dba 对表进行删除/更新?

.net - 在控制台应用程序中读取命令行参数的最佳方法

c# - ASP.NET在运行时显示和隐藏图像

python - 运行每日 SQL 查询和通过电子邮件发送结果的最佳方法

mysql - SQL - 从大数据集中返回最新的多条记录