Hi Adel M,
Welcome to Microsoft Q&A and thank you for posting your query here!
The issue where an Azure App Service cannot connect to an Azure SQL Database despite having the SQL Server firewall and Virtual Network rules configured often relates to additional network and DNS configurations beyond just IP whitelisting.
Here are key points and steps to verify and resolve this:
Private Endpoint and DNS Resolution If your Azure SQL Database is configured with a private endpoint, the App Service must resolve the SQL server's fully qualified domain name (FQDN) to the private IP address of that endpoint, not the public IP. This requires proper configuration of Azure Private DNS zones (privatelink.database.windows.net) and ensuring the App Service's VNet integration supports DNS resolution to that private zone. Without correct DNS setup, the App Service will attempt to connect via the public IP and may fail.
Network Security Groups (NSGs) and User-Defined Routes (UDRs) Verify that NSGs and any UDRs on your subnet(s) or on the VNet gateway allow outbound traffic from the App Service to the SQL Database on port 1433. Incorrect NSG or route rules can block this traffic even if firewall rules seem correct.
Service Endpoints and VNet Rules IP firewall rules allowing all App Service outbound IPs only work if the SQL Server network access settings include public network access. If VNet service endpoints or private endpoints are configured, IP firewall rules might be bypassed. Service endpoints require the subnet to have the SQL service endpoint enabled and added to the SQL Server’s VNet rules.
Verification of IP and DNS used by App Service Use the Kudu Console available at https://<your-app-service-name>.scm.azurewebsites.net/DebugConsole to run commands like nslookup <sql-server-name> to check if DNS resolves to expected private or public IP. Also, application logs and Azure SQL diagnostic logging can help confirm connection attempts and source IP.
Recommended next steps:
Double-check if Private Endpoint is configured for your SQL Database and ensure the App Service’s DNS can resolve to it correctly.
- Review NSG rules on the subnet hosting the private endpoint and, on any subnet, used by the App Service VNet integration.
Confirm port 1433 is allowed outbound from the App Service to the database.
If using service endpoints, verify they are enabled and properly configured on the VNet subnet.
Monitor connection attempts using Azure SQL diagnostic logs for further clues.
For detailed guidance, please refer to Microsoft official documentation below:
- Troubleshoot Common Connection Issues in Azure SQL Database: https://free.blessedness.top/en-us/azure/azure-sql/database/troubleshoot-common-errors-issues?view=azuresql
Tutorial on Azure SQL Database Private Endpoint Setup: https://free.blessedness.top/en-us/azure/private-link/tutorial-private-endpoint-sql-portal
Azure SQL Database Firewall and Virtual Network Configuration: https://free.blessedness.top/en-us/azure/azure-sql/database/firewall-configure?view=azuresql
This comprehensive approach should help identify why the App Service cannot establish a connection and how to adjust networking, DNS, and security setups accordingly.
Please do let me know if you have any question on this.
Thanks,
Harish.