7
votes

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?

1
I am sorry but I need to ask.... why? why would you need such a thing?Dalorzo
I want to limit the number of connections to the SQL server to limit the load for one application. I want to analyze the current situation with no connection limit in the pool and what happens if I limit it to 4 connection.phoad
Are you suggesting that the connection pool may have a performance impact in your SQL Server and because of that you want to limited?Dalorzo
I do not know that much. I have clients that connect to SQL server and I have source that I read from. I am trying to increase the number of threads that I use to connect my source to eliminate the effect of ping time, but I do not want all of the threads to write to SQL server at once, which might cause huge load and perhaps affect responsiveness to the clients' requests. Is it reasonable?phoad
Let me put it this way; limiting the connection pool is not the answer you are looking for. I would advice that you reframe your question with all this information you just shared instead of looking for ways to limit the connection pool. It looks like this is a classic xy problem.Dalorzo

1 Answers

10
votes

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

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