89

This is my database connection string. I did not set max pool size until now.

public static string srConnectionString = 
                       "server=localhost;database=mydb;uid=sa;pwd=mypw;";

So currently how many connections does my application support? What is the correct syntax for increasing the connection pool size?

The application is written in C# 4.0.

3
  • 11
    if you don't have a problem, leave it as the default. Commented Oct 16, 2011 at 12:01
  • currently yes but i think it might cause problems at peak moments. So i prefer set higher than default. as i read default is 100 am i right ? Commented Oct 16, 2011 at 12:03
  • 4
    The default Connection Pool size of 100 is documented by Microsoft at learn.microsoft.com/en-us/dotnet/framework/data/adonet/… and likely other places. Commented Oct 19, 2017 at 14:58

3 Answers 3

110

Currently your application support 100 connections in pool. Here is what conn string will look like if you want to increase it to 200:

public static string srConnectionString = 
                "server=localhost;database=mydb;uid=sa;pwd=mypw;Max Pool Size=200;";

You can investigate how many connections with database your application use, by executing sp_who procedure in your database. In most cases default connection pool size will be enough.

6
  • 4
    Is there another way of setting the Max and Min poolsize than via the connectionstring? I would prefer to do it in code...
    – Jos
    Commented Oct 23, 2012 at 12:06
  • What happens when setting the 'max pool size' to, let say 30. When all the slots filled with 'in-use' and 'idle connections', will the idle connections be closed automatically to make room for new connections?
    – Pierre
    Commented Feb 22, 2016 at 12:54
  • 5
    @Pierre - you'll receive an error similar to the following: System.InvalidOperationException: Timeout expired. 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. at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) at System.Data.SqlClient.SqlConnection.Open() Commented Aug 7, 2017 at 23:17
  • What is your reference for 100 connections by default? Commented Oct 10, 2017 at 14:20
  • The first paragraph of the "Adding Connections" section of the Documentation article SQL Server Connection Pooling (ADO.NET) states that 100 is the default max pool size. (learn.microsoft.com/en-us/dotnet/framework/data/adonet/…) Seen 2019-09-14
    – Jahaziel
    Commented Oct 14, 2019 at 16:13
17

"currently yes but i think it might cause problems at peak moments" I can confirm, that I had a problem where I got timeouts because of peak requests. After I set the max pool size, the application ran without any problems. IIS 7.5 / ASP.Net

1
  • 5
    This is not an answer Commented Sep 3, 2020 at 3:32
-7

We can define maximum pool size in following way:

                <pool> 
               <min-pool-size>5</min-pool-size>
                <max-pool-size>200</max-pool-size>
                <prefill>true</prefill>
                <use-strict-min>true</use-strict-min>
                <flush-strategy>IdleConnections</flush-strategy>
                </pool>
2
  • 2
    What file is this? Commented Jun 15, 2020 at 13:49
  • it is not clear that what file is this, if it is a webconfig then where should we add this <pool> tag. Commented Aug 23, 2021 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.