Just as all Azure Web Apps need configuration values, most applications also need to have database Connection String values configured. With Azure Web Apps the Connection Strings are stored/retrieved in a very similar fashion as Azure Web App Application Settings. Connection Strings are also Key / Value pairs of String values, but are separated out into their own section.
Connection Strings are typically used to store the connection information for one or more databases the Web App needs to connect to for storing and retrieving data. The Connection String types supported are SQL Database, SQL Server, MySQL, PostgreSQL, and Custom. Most often the Connection Strings used will be for some kind of SQL RDMS, but the Custom type allows for an additional Connection String to be configured any other type of database connection necessary (such as Cosmos DB and Azure Storage).
As with Application Settings, the Connection Strings are accessed as normal from .NET code and the values will come from what is set within the Azure Portal. In other development environments (Node.js, Java, PHP, Python) the Connection Strings are exposed to code as Environment Variables. Additionally, the Connection Strings are editable within the Azure Portal, but are read-only when access through code.
Connection String within the Azure Portal
Managing the Connection Strings for an Azure Web App is performed through the Azure Portal.
Here are the necessary steps for locating and accessing the Connection Strings for an Azure Web App within the portal:
- Open the Azure Portal via https://portal.azure.com
- Navigate to the Azure App Service Web App within the portal.
- Under Settings open up the Configuration option
- The Connection strings section can be used to manage the settings for the application.

Add / Edit Connection Strings
When creating and/or editing Connection Strings (such as through Configuration -> Connection strings in the Azure Portal) the connection strings consist of a Key / Value pair for the name and value of the connection string. However, they also include another Type
value set on the Connection String that defines what type of connection string this is. This helps specify if the connection string is used for a Azure SQL Database, SQL Server, or other types of databases and services.
There are several different Type
options available for the Connection Strings:
MySQL
– MySQL serverSQLServer
– Microsoft SQL Server (such as that running in a VM)SQLAzure
– Azure SQL DatabasePostgreSQL
– PostgreSQL serverCustom
– a general type used for any other database / service connection string (such as Azure Storage, Cosmos DB, or others)

Access Connection Strings using ASP.NET Core (C#)
Using C# code in .NET Core to retrieve the Connections Strings for the Azure Web App is done using the standard ASP.NET Core dependency injection pattern in the following code example:
using Microsoft.Extensions.Configuration;
namespace MyNamespace
{
public class MyClass
{
private IConfiguration _configuration;
public SomeClass(IConfiguration configuration)
{
_configuration = configuration;
}
public SomeMethod()
{
// retrieve App Service connection string
var myConnString = _configuration.GetConnectionString("MyDbConnection");
}
}
}
Access Connection Strings using .NET Framework (C#)
Retrieving the Connection Strings for the Azure Web App is performed from .NET using the ConfigurationManager class in a very similar fashion as how Application Settings are retrieved.
Here’s an example of retrieving a Connection String from C# code:
using System.Configuration;
var key = "MyDBConnString";
string value = ConfigurationManager.ConnectionStrings[key]
.ConnectionString;
Access Connection Strings from Node.js
In Node.js the Azure Web App Connection Strings are exposed as Environment Variables. Accessing the Connection Strings through the Environment Variables is exactly like accessing Application Settings, but with a different string prefixing the Connection String key name.
Here are the Connection String Environment Variable key name prefixes:
- SQL Database prefix is
SQLAZURECONNSTR_
- SQL Server prefix is
SQLCONNSTR_
- MySQL prefix is
MYSQLCONNSTR_
- Custom prefix is
CUSTOMCONNSTR_
Here’s an example of retrieving a Connection String from Javascript running on Node.js:
var value = process.env.SQLCONNSTR_MyDBConnString;
Access Connection Strings from Java
Azure Web App Connection Strings are exposed to Java code as Environment Variables. These are accessed in the same method as Application Settings except with different string prefixes on the Connection String key names.
Here are the Connection String Environment Variable key name prefixes:
- SQL Database prefix is
SQLAZURECONNSTR_
- SQL Server prefix is
SQLCONNSTR_
- MySQL prefix is
MYSQLCONNSTR_
- Custom prefix is
CUSTOMCONNSTR_
Here’s an example of retrieving a Connection String from Java code:
String value = System.getenv("SQLCONNSTR_MyDBConnString");
Happy coding!
There is a typo. Custom prefix is not “CUSTOM_CONNSTR_” but “CUSTOMCONNSTR_”
Oops, thanks! 🙂
Hi Chris!
Do you know if the Connection Strings are encrypted at rest inside the Azure Management Portal?
That I do not know. I haven’t seen any mention of it in documentation. What’s your use case where you need to have that done?
Hi Chris, I am trying to connect to azure table and using my local.settings.json file to define the connection string as follows
“IsEncrypted”: false,
“Values”: {
“AzureWebJobsStorage”: “UseDevelopmentStorage=true”,
“AzureWebJobsDashboard”: “”,
“FUNCTIONS_WORKER_RUNTIME”: “java”,
“SQLCONNSTR_storageConnectionString”:”DefaultEndpointsProtocol=https;AccountName=sdw-content;AccountKey=IIWAet8PWthpod86qc9DmiM82AO5d7576WVmKxFFHM395pLkG4KIA0mfFNf67CAnkbZpUsxNLedCOiin5cp1RQ==;TableEndpoint=https://sdw-content.table.cosmosdb.azure.com:443/;”
}
and reading the connection string in my java code which is spring boot application
storageAccount = CloudStorageAccount.parse(System.getenv(“storageConnectionString”));
all the time I am getting storageAccount is null. Please help me how can I fix this issue
You’ll want to name your connection string “storageConnectionString” within the local.settings.json file. Then you’ll be able to access the “SQLCONNSTR_storageConnectionString” environment variable from code. You just have them swapped in the snippets you’ve shared.
Hi Chris,
Hey we have Postgres SQL DB created and we want to access the connection string within the Jave webapp we are going to deploy within the Azure environment. Do you think we will have to define a Connection String (wtithin the Application Settings of the Web-App in Azure Portal) variable (“CUSTOMCONNSTR_outVariableName”) and then use it within the Java code to connect to the DB? sorry if this sounds basic but I am new to Java side of things for connecting the Azure Postgres SQL DB. Thank you.
Yes you could add it to application settings in the Azure Web App and then get it from Java via the environment variable.
Thank you Chris, just wanted to confirm that I should be defining the variable as this:–> “CUSTOMCONNSTR_outVariableName” is that correct? My database is PostgresSQL on Azure.
Just name it “outVariableName” and it will be made available as an environment variable named “CUSTOMCONNSTR_outVariableName”.
I have spring boot application which connects to Postgres database. while i deployed this spring boot application as Web-apps in Azure, i tried to access database user name and password and Connection string as below in spring boot application/properties. But i am getting JDBC connection error after launching from Azure. I am accessing azure environment variables as below in my springboot application.properties.
spring.datasource.url =${CUSTOMCONNSTR_outVariableName}
spring.datasource.username = ${DBUSER}
spring.datasource.password = ${DBPASSWORD}
org.postgresql.Driver=${DBDRIVER}
outVariableName i have set as connection string in jdbc:postgresql://***.port/database=postgres in azure app where i have given username and password of DB as part of Application settings in DBUSER/DBPASSWORD/DBDRIVER. But still no luck. Please suggest what is the issues?why environment variables not accessed in spring boot application.properties?
Make sure you are accessing the Environment Variables correctly for the DBUSER and DBPASSWORD app settings, and the CUSTOMCONNSTR_outVariableName connection string.
I have spring boot applicaiton which is using MYSQL as backend. I have added Connection String for MySql as below spring.datasource.url=${MYSQLCONNSTR_outVariableName}
spring.datasource.username=${SPRING_DATABASE_USER}
spring.datasource.password=${SPRING_DATABASE_PASSWORD}. When i try to access the mysql db from Azure, i am getting below error “org.springframework.security.authentication.InternalAuthenticationServiceException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, ${MYSQLCONNSTR_outVariableName}”