0
0
Azurecloud~5 mins

Application settings and connection strings in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Application settings and connection strings store important information like keys and URLs that your app needs to work. They keep this data separate from your code so you can change settings without changing the app itself.
When you want to keep your database login details safe and separate from your app code.
When you need to change an API key without updating your app's code.
When you want to use different settings for development and production environments.
When you want to quickly update a service URL your app connects to without redeploying.
When you want to manage secrets like passwords securely in Azure App Service.
Commands
This command sets an application setting named MySetting with the value HelloWorld for the Azure web app named example-app. It helps you add or update settings your app uses.
Terminal
az webapp config appsettings set --name example-app --resource-group example-rg --settings MySetting=HelloWorld
Expected OutputExpected
{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/sites/example-app/config/appsettings","name":"appsettings","type":"Microsoft.Web/sites/config","location":"East US","properties":{"MySetting":"HelloWorld"}}
--name - Specifies the name of the web app.
--resource-group - Specifies the resource group of the web app.
--settings - Defines the key-value pairs for application settings.
This command sets a connection string named MyDb for the Azure web app example-app. It stores the database connection details securely for the app to use.
Terminal
az webapp config connection-string set --name example-app --resource-group example-rg --settings MyDb=Server=tcp:myserver.database.windows.net;Database=mydb;User Id=myuser;Password=mypassword; --connection-string-type SQLAzure
Expected OutputExpected
{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/sites/example-app/config/connectionstrings","name":"connectionstrings","type":"Microsoft.Web/sites/config","location":"East US","properties":{"MyDb":"Server=tcp:myserver.database.windows.net;Database=mydb;User Id=myuser;Password=mypassword;"}}
--connection-string-type - Specifies the type of database or service the connection string is for.
This command lists all application settings for the web app example-app so you can verify what settings are currently set.
Terminal
az webapp config appsettings list --name example-app --resource-group example-rg
Expected OutputExpected
[{"name":"MySetting","value":"HelloWorld"}]
--name - Specifies the web app name.
--resource-group - Specifies the resource group.
This command lists all connection strings for the web app example-app so you can check the stored connection details.
Terminal
az webapp config connection-string list --name example-app --resource-group example-rg
Expected OutputExpected
[{"name":"MyDb","connectionString":"Server=tcp:myserver.database.windows.net;Database=mydb;User Id=myuser;Password=mypassword;","type":"SQLAzure"}]
--name - Specifies the web app name.
--resource-group - Specifies the resource group.
Key Concept

If you remember nothing else from this pattern, remember: keep your app settings and connection strings separate from your code so you can update them safely without changing your app.

Common Mistakes
Putting sensitive information like passwords directly in the app code.
This makes it hard to change secrets and risks exposing them if the code is shared.
Use Azure App Service application settings and connection strings to store secrets securely.
Not specifying the correct connection string type when setting connection strings.
Azure may not handle the connection string properly, causing connection failures.
Always use the --connection-string-type flag with the correct type like SQLAzure or MySQL.
Forgetting to verify settings after setting them.
You might think the setting was applied but it could have failed or been mistyped.
Run the list commands to confirm your settings and connection strings are set correctly.
Summary
Use 'az webapp config appsettings set' to add or update app settings for your Azure web app.
Use 'az webapp config connection-string set' to securely store database connection details.
Verify your settings with 'az webapp config appsettings list' and connection strings with 'az webapp config connection-string list'.