Azure SQL Connection Timing Out all of a sudden

Copper Contributor

Hi All

 

I have a Azure Function App and IoT Hub where my incoming data(once per min per device) gets saved to an SQL database. This has been working well for sometime, but in last day or so, i noticed message are not being saved into my SQL DB. After some investigation using Application Insight, I noticed the following error: It seems my pooling and DTU have increased suddenly. Can you someone help or advice on what could have gone wrong? Is there any server maintenance or issues going on in West Europe?

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.
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
1 Reply

@DJ200 the error message you received indicates that the timeout period elapsed before obtaining a connection from the pool. 

If your queries take longer to execute, you might encounter timeout errors. You can increase the SQL commands timeout by Setting the SqlCommand.CommandTimeout property to a value that accommodates your function's execution time (e.g., 10 minutes or 600 seconds).

 

Check the Azure Service Health dashboard for any ongoing issues or maintenance activities in the West Europe region. Sometimes, transient issues or maintenance can impact service availability. If there are any reported incidents, it might explain the sudden increase in pooling and DTU (Database Transaction Units).

 

Also, please review your SQL database performance metrics. Are there any long-running queries or resource-intensive operations? To improve performance, consider optimizing your queries, indexing, and database schema. Monitor the Database Transaction Units (DTUs) and adjust your database tier if needed. 

 

I will also recommend reading the Timeout expired messages when connecting to SQL Server documentation.

---

If this post is helpful, please give my response a thumbs up! You can also mark it as the solution to help others find it easily.