The error message you’re encountering, which mentions that the database is "not currently available," often arises from transient connection issues or configuration problems within Azure App Service or SQL Database settings. First, ensure the SQL Database is indeed accessible by trying to connect directly from another tool like SQL Server Management Studio or Azure Data Studio. This can confirm if the issue is specific to your app or if there are broader connectivity issues with the database.
Check your firewall and network configuration in Azure. Go to the SQL Database in the Azure portal and verify that its firewall rules allow the outbound IP address of your Azure App Service. If your SQL Database is within a Virtual Network (VNet), confirm that the App Service has been configured to access this VNet as needed.
It's also important to confirm the accuracy of your connection string and authentication method. Review the connection string to ensure it’s configured correctly and that the authentication mode you’ve selected (such as Managed Identity, SQL Authentication, or Azure AD) aligns with your setup. If you’re using a managed identity, make sure this identity has been granted the necessary role, like db_datareader
or db_datawriter
, on the SQL Server. In SQL Server, add this identity and assign the required permissions to avoid authentication issues.
Sometimes, transient deployment issues can cause connectivity errors. Stopping and restarting the App Service or redeploying the container can help reset the environment. If the issue persists, you might want to enable diagnostic logging for both the SQL Database and App Service in the Azure portal to gather more detailed error information, which can provide clues on any persistent configuration or connectivity issues.
For more details on setting up firewall rules for SQL databases, check this Azure documentation. For guidance on using managed identities with SQL, refer to this guide.