What are the different ways of setting up Application Pool ( DB connections) restart for an Azure portal APP

ramesh kancherla 1 Reputation point

What are the different ways to automate Application Pool ( DB connections) restart for an Azure portal APP .

Both on portal and Command line via CLI/Powershell.

Azure SQL Database
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,774 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 19,601 Reputation points

    Hi @ramesh kancherla ,

    Thank you for clarifying the question above. The following information is based on the understanding that the application is running on an Azure VM.

    DB connection pool is a client-side construct, and the Database Server does not maintain it. It is maintained in memory of webApplication if you are connecting via ADO.NET, ODBC etc. If you are using JDBC driver form a Java application, it is maintained in-memory of one of the middleware (ref: Using JDBC connection pooling).

    There isn't any direct way to achieve App Pool restart when DB Connection pool is almost full. However, there are multiple other ways through which this can be achieved. One of the ways is to use the Exception being collected by ApplicationInsights, to trigger a restart of application pool through Azure Automation. This would involve:

    1. Create an Azure monitor log alerts rule for the exception that occurs for DB Connection Pool exhaustion in recent past (InvalidOperationException: Timeout expired prior to obtaining connection from connection pool). For more information, please refer to: Create, view, and manage log alerts using Azure Monitor

    2. Use this alert to trigger an Azure Automation runbook. This runbook could contain code to run a command in VM, to restart IIS app pool. Please refer to this link for more information.


    While you may choose to restart Application Pool every time the DB connection pool is full, it is not a good approach. Instead, the focus should be on trying to resolve this issue. Following are the common causes and respective suggestions to mitigate them:

    a. The current limit of maximum connection count in connection Pool is not enough: For ADO.NET the default value is 100 which sometimes is not enough. You may increase this count in the connection string to a higher value and observe its impact. This is particularly useful when resources required for communication with DB is not a lot, not advisable for resource extensive connections.

    b. Connections are not getting closed/disposed properly: For .NET based application, using{} block for SQLConnection ensures that the connection is disposed when leaving the block context. Ref: SQLConnection Class.

    c. Need to increase Web Server count: This is particularly beneficial when your web servers are remarkably busy and need to load balance the incoming requests. Increasing the count of web servers will allow for more instance of Connection pool to be created, thereby reducing the error.

    d. Database performing slow: It may be the case that the SQL Server is servicing requests slowly, thereby keeping the connection alive. Performance review and tuning of the database/DB Server should help in this regard.

    Please let me know if you have any questions.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.