sql服务器连接必须闲置多长时间才能被连接池关闭? [英] how long must a sql server connection be idle before it is closed by the connection pool?

查看:281
本文介绍了sql服务器连接必须闲置多长时间才能被连接池关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用.NET SqlClient数据提供程序连接到sql server的客户端服务器应用程序-非常标准的东西。默认情况下,连接池管理器将关闭数据库连接并将其从池中删除之前,连接必须闲置多长时间?

I have a client-server app that uses .NET SqlClient Data Provider to connect to sql server - pretty standard stuff. By default how long must connections be idle before the connection pooling manager will close the database connection and remove it from the pool? What setting if any controls this?

此MSDN文档仅说


连接池在空闲了一段时间后从池中删除了一个连接。长时间,或者如果池管理程序检测到与服务器的连接已断开。

The connection pooler removes a connection from the pool after it has been idle for a long time, or if the pooler detects that the connection with the server has been severed.


推荐答案

几年前,答案是这种情况,但是现在已经改变了,因此您可以参考并撰写摘要:)

A few years ago the answer beneath was the situation, but now it's changed so you can refer to the source and write up a summary :)

旧答案

这篇出色的文章告诉我们我们需要知道的内容,通过反射来揭示con的内部工作原理连接池。

This excellent article tells us what we need to know, using reflection to reveal the inner workings of connection pooling.

据我了解,封闭的连接会定期以半随机间隔进行清理。清理过程每2分钟到3分钟50秒之间运行一次,但是它需要运行两次,才能正确关闭关闭的连接。因此,在关闭 40分钟后的7分钟内,应正确关闭基础sql连接,但可能只有2分钟。在撰写本文时,在进程中创建的第一个连接池将始终具有3min 10s的计时器间隔,因此您通常会看到在ADO对象上调用Close()之后,在3min 10s至6min 20s之间关闭s​​ql连接。

From how I understand it, 'closed' connections are cleaned up periodically on a semi-random interval. The cleanup process runs somewhere between every 2min and 3min 50s, but it needs to run twice before a 'closed' connection will be properly closed. Therefore after 7min 40s of being 'closed' the underlying sql connection should be properly closed, but it could be as short as 2min. At the time of writing the first connection pool created in a process would always have a timer interval of 3min 10s, so you'd normally see sql connections being closed somewhere between 3min 10s and 6min 20s after you call Close() on the ADO object.

很明显,此代码使用了未记录的代码,因此将来可能会更改-甚至可能自撰写该文章以来就已更改。

Obviously this uses undocumented code so could change in future - or could even have changed since that article was written.

这篇关于sql服务器连接必须闲置多长时间才能被连接池关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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