Sql – Increasing the Max Pool Size and performance

asp.netconnection-poolingsqlsql server

In my ASP.net website I have a connection to a SQL Server Express database. And sometimes I do get lot of errors like

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.

After searching for the error I found that it may be due to unclosed SQL Server connections. But I have used SQL Server connections properly and I have disposed it properly.I have used using-statement to dispose the connection. In my application I get a lot of requests (connections to SQL Server database) at some peak time of the day.

So I am planning to increase the max pool size. Now I have not specified it in my connection string. So it will be 100 (default). I am planning it to increase to 20000 so that I won't get the error.

So does increasing to the max pool size to this number will cause any problem? Does increasing the max pool will cause any performance problem?

EDIT:
Below is a sample of how i used Using in my code

Using con1 As New SqlConnection
    con1.ConnectionString = "" //conn string here
    con1.Open()
    doSomething()      
End Using 

Using con2 As New SqlConnection
                con2.ConnectionString = "" //conn string here
                con2.Open()
                doSomething()
            Using con3 As New SqlConnection
               con3.ConnectionString = "" //conn string here
               con3.Open()
               doSomething()       
            End Using

End Using 

Catch ex As Exception

End Try

EDIT:
I just tested by setting Max pool size to 20000 in my application to check if max pool is really causing the problem.I was expecting to not get this exception any more. But it didn't solve the problem or may not be the reason of the error. After setting max pool also i got above error about 50 times in a duration of 3 hours. So I doubt is it really due to pool size? The error message states that "This may have occurred because all pooled connections were in use and max pool size was reached". So is there any other case where the same error message shown? Please help.

Best Answer

You can increase the pool size if you want. There are two downsides:

  1. More connections mean more resource usage.
  2. SQL Server has a connection limit of about 30k connections. When you exhaust it you will lose availability.

I recommend going higher more slowly. Don't increase the pool size to 20k immediately. Think about what 20k connections would mean: It would mean roughly 20k threads (or less if a single thread uses more than one connection) executing at the same time. If you are in that spot you probably have load problems.

Why do you even need that many connections? For web apps, you usually have only one connection open at the same time per running request. A few hundred should be enough for most cases.

Try to shorten the duration that each connection must be open.