Azure App Service won't connect to Azure SQL Database

Ian Brian 11 Reputation points
2025-08-22T04:46:32.18+00:00

I have an Azure App Service, which is a .NET Framework MVC 5 web site that after running for years will suddenly not connect to SQL Server. “Check Connection Strings” in “Diagnose and Solve Problems” fails with this error “Code:GatewayTimeout The gateway did not receive a response from 'Microsoft.Web' within the specified time period.”

One of the deployment slots is a staging site. This has the same code (which runs without connection issues) with the connection string that fails for the production site. “Check Connection Strings” passes. The staging site can connect to both the production and staging databases.

I have consulted MS support and upgraded the app service plan as advised because they observed memory issues. They seem to be focussing on perceived problems with the application as the cause of the site failing to run. However, I think these are red herrings given that the application is running in staging. I think that attention can turn to other issues once the connectivity issue as been remedied. My question is what should I check to discover what is preventing the production site connecting to a database that the staging site can connect to when the code in both cases is the same.

Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2025-08-26T17:28:00.74+00:00

    Hi Ian Brian

    the fact that staging works while production doesn't, with identical code, means the issue is almost certainly environmental. Here's a focused checklist to help you pinpoint the root cause:

    Connection Strings

    • Compare connection strings in both slots via Azure Portal → App Service → Configuration.

    Ensure no hidden differences (e.g. trailing spaces, casing, or slot-specific overrides).

    Check if the connection string is marked as a slot setting—this prevents it from swapping between slots.

    Managed Identity (if used)

    • Confirm the production slot’s identity is enabled and has the correct Azure SQL permissions.
    • Check if the identity is System-assigned or User-assigned, and whether it differs between slots. SQL Server Firewall

    Verify that production slot’s outbound IPs are whitelisted in Azure SQL firewall settings.

    You can find outbound IPs under App Service → Properties → Outbound IP Addresses.

    Application Insights

    • Look for SQL connection exceptions or timeouts in production logs.
    • Compare telemetry between staging and production to spot anomalies.

    Deployment Slot Behavior

    Check if any startup tasks, warm-up scripts, or health checks differ between slots.

    Try swapping staging into production temporarily to isolate whether the issue is slot-specific or environment-specific.

    Clean Restart

    Restart the production slot to flush any stale DNS or socket connections.

    • Consider redeploying the production slot from scratch if corruption is suspected.

    You can mark it 'Accept Answer' if this helped you.

    Regards,

    Vishvani

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.