如何重置 Azure 中的连接池(错误:已达到最大池大小)?

如何重置 Azure 中的连接池(错误:已达到最大池大小)?

我在 Azure 网站中收到以下错误,我正在努力修复它:

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.

我该如何重置或增加游泳池?

答案1

您可以像其他数据库一样增加 Azure 中的 SQL 连接池。默认情况下,您将获得 100 个连接。如果您的系统上没有那么多用户,您可能需要检查是否在不再使用连接时关闭/处置连接。

connectionString="Server=XXX;Database=XXX;User Id=XXX;password=XXX;
    connection timeout=0;Max Pool Size = 500;Pooling = True"

答案2

您可以运行启动命令来更改应用程序池空闲超时。从启动任务调用的 cmd 文件运行类似下面的命令(此示例禁用超时):

%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00

使用类似的技术,您可以在达到特定内存阈值后回收应用程序池(请参阅本文

答案3

调整连接字符串配置(如Max Pool Size = 500;在 web.config 中),以匹配当前 Azure SQL 数据库层最大连接数

有关每个 Azure SQL 层资源限制的详细信息:https://azure.microsoft.com/en-us/documentation/articles/sql-database-resource-limits/

答案4

SqlConnection.ClearAllPools(); 在打开与数据库的新连接之前添加此项。

相关内容