Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLConnection pool size and active connection count in C#

In C# it is possible to enable/disable Connection Pooling by using "Pooling=True" and "Max Pool Size=XY" in connection string.

Like: What is maximum allowable value of "Max Pool Size" in sql connection string

Is it possible to ask how many connections to SQL server is active and what is the current pool size programmatically?

like image 607
phoad Avatar asked Aug 11 '14 21:08

phoad


People also ask

What is the max pool size in connection pool?

A connection pool is created for each unique connection string. When a pool is created, multiple connection objects are created and added to the pool so that the minimum pool size requirement is satisfied. Connections are added to the pool as needed, up to the maximum pool size specified (100 is the default).

What is the ideal DB connection pool size?

For optimal performance, use a pool with eight to 16 connections per node. For example, if you have four nodes configured, then the steady-pool size must be set to 32 and the maximum pool size must be 64. Adjust the Idle Timeout and Pool Resize Quantity values based on monitoring statistics.

Does using SqlConnection close connection?

The sqlConnection will close the connection after it will pass using block and call Dispose method. SqlConnection. Dispose() equal to SqlConnection.


1 Answers

You can use NumberOfActiveConnections or NumberOfPooledConnections ADO.NET performance counter:

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/performance-counters

like image 177
Vlad Rudenko Avatar answered Oct 06 '22 01:10

Vlad Rudenko