SQLConnection pool size and active connection count in C#
Asked Answered
E

1

11

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?

Expansion answered 11/8, 2014 at 21:56 Comment(4)
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.Expansion
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?Expansion
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.Semiautomatic
I found a similar question and answer. It helped me #216507Expansion
G
12

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

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

Graehl answered 6/6, 2015 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.