Roadmap › ADO.NET — Connected & Disconnected Data Access › Module: Transactions, Pooling and Performance
Lessons in this course (9)
7. Connection pooling
Intermediate★ Must knowLesson 7 of 9
- Opening a physical connection is expensive (TCP, TLS, login). ADO.NET keeps a pool per unique connection string (and per Windows identity for integrated security).
Open()takes a connection from the pool;Close()/Dispose()returns it.- Defaults (SqlClient):
Min Pool Size=0,Max Pool Size=100,Pooling=true,Connection Timeout=15. - Pool exhaustion ("Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool") = connections not disposed, long-running transactions, or too many concurrent requests.
- Different connection strings (even a different space/order) create separate pools — build them once from config.
- Keep connections open as briefly as possible: open late, close early, always with
using.