I am getting the below error in my Azure website and am scrambling to fix it:
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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: 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.
How can I reset the pool or increase it?
You can increase the SQL Connection Pool in Azure the same was as any other database. By default you get 100 connections. If you don't have that many users on your system you may want to check that you are closing/disposing connections when they're no longer in use.
You can run a startup command to change the app pool idle timeout. Run something like this from a cmd file called from a Startup task (this example disables timeout):
Using a similar technique, you can recycle the app pool after hitting a certain memory threshold (see this article)
Adjust your connection string config like
Max Pool Size = 500;
in web.config to match your current Azure SQL database tier max connectionsFor more info about each Azure SQL Tier resource limitations: https://azure.microsoft.com/en-us/documentation/articles/sql-database-resource-limits/
SqlConnection.ClearAllPools(); Add this before opening a new connection with database.