Intermittent Timeout Errors in Azure SQL Database Connection from .NET Core App
I'm migrating some code and Hey everyone, I'm running into an issue that's driving me crazy. I'm experiencing intermittent timeout issues when my .NET Core application tries to connect to an Azure SQL Database. Sometimes it connects without problems, but other times I get a `Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.` behavior. My connection string looks like this: ```plaintext Server=tcp:myserver.database.windows.net,1433;Initial Catalog=mydatabase;continue Security Info=False;User ID=myuser;Password=mypassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30; ``` I have tried increasing the `Connection Timeout` to 60 seconds, but that hasn’t resolved the scenario. Additionally, I’ve implemented connection pooling, and I’m using `Microsoft.Data.SqlClient` version 3.1.6. I’m using async/await for database calls, but I’m unsure if that might be causing issues with connection handling. My app is hosted in Azure App Service with a Basic tier plan. I noticed the scenario occurs more frequently during peak usage times. I’ve also reviewed the Azure SQL Database metrics and observed spikes in DTU usage during these timeouts, suggesting that the database might be under heavy load. However, I have configured the maximum pool size to 100 connections in my application. Is there a best practice for handling these types of intermittent connection issues, particularly in relation to scaling the Azure SQL Database or optimizing the connection pool settings? My development environment is macOS. How would you solve this? This is happening in both development and production on Windows 11. What's the best practice here?