Hi Tiffany Kwan,
Welcome to Microsoft Q&A Forum!
Have a good day and I hope you're doing well!
During our review of the error you encountered on SharePoint Server ("System.AggregateException: One or more errors occurred… all pooled connections were in use and max pool size was reached"), we have identified this as an issue related to the Connection Pooling mechanism in .NET/SQL Server.
Based on our analysis and references from similar cases, this error typically occurs when:
- The application or custom code in SharePoint opens a connection to the database but does not close it properly (connection leak).
- Too many connections are opened simultaneously, causing the connection pool to reach the Max Pool Size limit (default is usually 100).
- Some queries or operations to SQL Server take a long time to process, preventing connections from being released promptly.
When all connections are in use, new requests cannot obtain a connection from the pool. The system will wait until the timeout period expires and return the error as seen.
1. Review code and database connections:
- Ensure all connections are closed or disposed of properly after use.
- If possible, apply the using syntax in .NET to automatically release resources:
- Avoid returning
SqlDataReaderorSqlConnectionwithout closing them from the calling side.
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(query, conn))
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
// process data
}
}
}
2. Increase the Max Pool Size value if it fits the actual load:
- You can add to the connection string:
Max Pool Size=200;
- However, this is only a temporary solution. The sustainable approach is to ensure connections are closed properly.
3. Monitor SQL Server:
- Use
sys.dm_exec_connectionsorsys.dm_exec_sessionsto check the number of open connections. - Analyze queries that are running long or are blocked.
Additional References
- Microsoft Docs: SQL Server Connection Pooling (ADO.NET)
- Microsoft Docs: SqlCommand.ExecuteReader Method
- This may have occurred because all pooled connections were in use and max pool size was reached
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link
I hope the information I provided will be partially useful. If I misunderstand or anything is unclear, or you have any concern, question, don't hesitate to let me know.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.