10

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?

Community
  • 1
  • 1
phoad
  • 1,801
  • 2
  • 20
  • 31
  • 1
    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 Aug 11 '14 at 22:06
  • 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 Aug 11 '14 at 22:18
  • 3
    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](http://meta.stackexchange.com/a/66378). – Dalorzo Aug 11 '14 at 22:23
  • I found a similar question and answer. It helped me http://stackoverflow.com/questions/216007/how-to-determine-total-number-of-open-active-connections-in-ms-sql-server-2005 – phoad Aug 12 '14 at 06:31

1 Answers1

11

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

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

Dan Jagnow
  • 1,175
  • 12
  • 28
Vlad Rudenko
  • 2,363
  • 1
  • 24
  • 24