I am very confused. I want to get a connection string in an Azure v3 function (.Net Core 3.1).
My local settings looks like
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true"
},
"ConnectionStrings": {
"DefaultConnection": "bla bla"
}
}
and in the function I do
string defaultConnection = Environment.GetEnvironmentVariable("ConnectionStrings:DefaultConnection");
This works fine locally but on Azure, defaultConnection is null. I defined the connection under the section Connection strings of the function's Application Settings.
Is my approach correct for Azure function v3?
You need to specify the connection string prefix (see documentation):
Environment.GetEnvironmentVariable("CUSTOMCONNSTR_DefaultConnection");