How to correctly set Connection String in Azure Web App?

Uhmazing34 30 Reputation points
2023-09-18T10:23:09.94+00:00

Hello,

I have set up an Azure Web App (App Service), which I have configured to be connected to an Azure Database for MySQL Flexible Server through VNet integration.

Everything works fine, but at some moments of the day there's an issue where the database cannot be found from within the application, which leads to connection drops.

I have not configured the Connection String of the Web App before, and I have the feeling that this might solve the issue.
However, what is the correct way to set the connection string?

If I go to the Azure Database for MySQL Flexible Server and click on "Connect", it shows the following connection details:

hostname=**
username=**
password={your-password}
ssl-mode=require

Would I just have to copy this and fill in my details like this?
hostname=** username=** password=** ssl-mode=require

Thank you in advance.

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
986 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ben Gimblett 4,560 Reputation points Microsoft Employee
    2023-09-18T14:26:49.4066667+00:00

    @Uhmazing34 -if you are already connecting in code , from the application, and the networking is working, then it sounds like you have a transient fault that may need to be investigated between the app and the database leading to connections getting dropped

    On the other part of the question

    You can use App Settings to manage the configuration values - this works nicely if you're also using the "slots" feature and you can use a key vault reference from the app settings to read through the password from key vault REF https://learn.microsoft.com/en-us/azure/app-service/app-service-key-vault-references?tabs=azure-cli

    MySQL for Flexible Server also supports managed identity - here you would be relying on the token derived from the App service managed identity REF https://learn.microsoft.com/en-us/azure/mysql/single-server/how-to-connect-with-managed-identity#creating-a-mysql-user-for-your-managed-identity

    In many cases this would be better than using basic authentication (username + password pair)


Your answer

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