От: | Аноним | ||
Дата: | 05.03.07 00:36 | ||
Оценка: | 12 (1) |
Q If an app makes 50 simultaneous connections to SQL Server™, there will be 50 connections in the connection pool. When are they removed from the pool? If their ConnectionLifetime is 0, which the documentation describes as using the maximum connection lifetime, how long is this?
A The logic behind removing connections from the pool is undocumented, but this has not prevented people from trying to discover it and write articles about it. The best one is probably SqlClient Connection Pooling Exposed — Reflection allows .NET developers to peer into the internals of SqlClient . You can also check out the following blog: ADO.NET The misunderstood "Connection Lifetime" managed pooler connection string keyword .
The basic idea is that connections left idle in the pool will be cleared at a random time between approximately four minutes and eight minutes, depending on implementation details. There is nothing that you can do short of using reflection, as shown in the article mentioned previously, to change this default.
The actual behavior for a connection with minimum pool size set is the same as for a connection without it. On closing the connection, the connection lifetime will be checked and it will be disposed. The managed pooler will notice that you have gone under the minimum pool size and it will open a new connection on a background thread. Connection lifetime has nothing to do with the connection pool idle time. Setting it to 0 equals the maximum value of int32.MaxValue, or 2147483647 seconds.