Having initially logged a support ticket for this the support team followed up with this response:
Essentially they are saying the accessing the Connection property fires up a new connection that isn't disposed. How are you supposed to access, for example:
dataContext.Connection.ConnectionTimeout
and dispose of the connection when you're done?
"Hi Mark,
Thank you for the feedback and for the additional details.
Following is further information about the error and two suggestions for implementing the scenario you describe.
Regarding the error, the provided code snippet calls the Connection properties on three occasions, which means three different connections:
here,
using
(dataContext.Connection)
here,
if
(dataContext.Connection.ConnectionTimeout != timeoutTarget)
and here
string
currentConnectionString = dataContext.Connection.ConnectionString;
In the first case, the connection is properly closed and disposed. In the other two cases the created connections are leaked.
During runtime, when the app goes through the code from the second and third cases, the two different newly created (or taken from the pool) connections are never closed. This means that although the exception happens for the code from the first case, the cause for it is that the other two calls to the Connection property exhausted the pool (the default pool size is 10 and when the connections are already leaked there is no connection for this code).
Regarding the scenario, one of the options is to use the Connect Timeout attribute in the connection string and to code a convenient value in seconds. For example:
<add name="ProjectManagementConnection"
connectionString="Data Source=.\SQLEXPRESS;
Initial Catalog=ProjectManagement;
Integrated Security=True;
Connect Timeout=20;
User Instance=False"
providerName="System.Data.SqlClient" />
</connectionStrings>
The other option is to use the ConfigurationManager and WebConfigurationManager classes (instead of accessing the context), in order to access, modify, and preserve the connection strings in the .config files. Both of them expose a ConnectionStrings property in which you can find the specific values."