设置Min Pool Size时,SQL数据库连接池的连接生命周期与复用规则?
Great question! Let's break this down clearly:
First off, the key point: The connection pool does NOT lock itself to a fixed set of connections for the Min Pool Size. It only guarantees that there will always be at least that number of active, usable connections in the pool. The specific connections themselves can change over time.
Here's why this happens:
- If a connection in the pool becomes invalid (e.g., the database restarts, the connection times out, or there's a network blip), the pool will discard that dead connection immediately. It will then create a new connection to replace it, ensuring the total number stays at or above your Min Pool Size setting.
- For example, if you set
Min Pool Size=2, and one of those two connections gets dropped by the database server, the pool won't just leave you with 1 connection. It'll spin up a fresh connection right away to get back to 2 active connections—so now you're working with a new pair, not the original two.
That said, if all connections in the pool stay healthy, the pool will absolutely reuse those same connections repeatedly. There's no "forced refresh" of the minimum connections on a regular schedule. The only time connections get replaced is when they're no longer usable.
A few extra notes to clarify:
- Some connection string parameters can influence this behavior. For example,
Connection Lifetimelets you set a maximum age for connections—once a connection hits that age, it'll be discarded when it's returned to the pool, and a new one will take its place (still keeping the min count intact). - Enabling
Validate Connection=truemakes the pool check a connection's validity before handing it out. If it's invalid, it's replaced immediately.
- Some connection string parameters can influence this behavior. For example,
内容的提问来源于stack exchange,提问作者TheDude

