how long must a sql server connection be idle before it is closed by the connection pool?

半腔热情 提交于 2019-11-29 17:46:47

问题


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?

This MSDN document only says

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.


回答1:


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 :)


Old answer

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

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.




回答2:


Please go through this:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28VS.80%29.aspx

The part

"The following table lists the valid names for connection pooling values within the ConnectionString."

seems to be of your interest.



来源:https://stackoverflow.com/questions/1136698/how-long-must-a-sql-server-connection-be-idle-before-it-is-closed-by-the-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!