Hi @Jasper Reddin
Thanks for the question and using MS Q&A platform.
it seems the SQL connections are not being properly released when using a Linux App Service with Hybrid Connection to an on-prem SQL Server.
1.Ensure Max Pool Size is set to a reasonable limit and use Connection Lifetime to recycle idle connections.
var connectionString = "Server=your_server;Database=your_db;User Id=your_user;Password=your_password;Max Pool Size=100;Connection Lifetime=300;";
2.Use using statements to ensure connections are properly closed.
using (var connection = new SqlConnection(connectionString)) { connection.Open(); }
For Entity Framework Core, ensure DbContext
is scoped correctly to avoid holding connections too long.
3.Ensure HCM is up to date and review logs for errors. Monitor active connections in Azure to identify unexpected connection retention.
4.App Service Configuration If enabled, ensure it doesn’t cause connection persistence issues. Consider a heartbeat request instead.Check default timeout settings that may interfere with connections.
5.Use the latest .NET runtime and Microsoft.Data.SqlClient version to avoid known bugs.
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.0" />
6.Enable Application Insights to track SQL connections. Use sp_who2
or sys.dm_exec_connections
in SQL Server to identify idle connections.
7.Ensure firewall settings do not block idle or long-running SQL connections.Check TCP Keep-Alive settings on Linux (sysctl -a | grep keepalive)
.
references:
SQL Server connection pooling (ADO.NET)
Connection Pooling
Azure App Service Hybrid Connections
https://learn.microsoft.com/en-us/azure/azure-monitor/app/codeless-app-service?tabs=aspnetcore
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-a-windows-firewall-for-database-engine-access?view=sql-server-ver16