C# multiple app instances with same connection string - max pool size reached

758 Views Asked by At
  1. There is a class library which describes a class called ServerTools that creates a connection to a database, and the connection string is hardcoded (not my code) with pool size = 10.

  2. My application creates an instance of ServerTools and uses canonized Parallel.Foreach to query the db. I control the connection resources using a semaphore. (The P.FE loop runs according to user input so I can't predict how many threads the TPL will create, that's why I control the db connections using a semaphore and not by limiting the number of created threads).

  3. For unrelated reasons, I need to run 3 instances of my app.

So eventually, I have 3 instances of my app, using 30 connections to the db.

When I ran these instances from different machines, everything was OK.

When I run these instances from the same machine, although these are different instances, I get an error saying:

"The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached."

So my question is: Is the connection pool configured per IP? I thought it will be configured per instance. Is there any work around other than running my instances using different machines? If some code changes were made so that each instance of ServerTools will have a different connection string, by making minor changes to the connection string so that the connection string won't be exactly the same, would it work?

Thanks!

0

There are 0 best solutions below