I have this local.settings.json in my local Azure function (Timer trigger)
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "python",
.
.
.
},
"ConnectionStrings": {
"sql_server": "valid connection string"
}
}
I managed to access the connection string locally using:
conn = os.environ["ConnectionStrings:sql_server"]
and my code runs okay.
But, when I deploy I get 'Failure Exception: KeyError: 'sql_server' [...] getitem raise KeyError(key) from None'.
I tried to execute in portal changing that line to:
conn = os.environ["sql_server"]
But nothing changed.
Does anyone know how I can call this method on Azure Web?
ConnectionStrings
in local settings file needs to be added in connection string section of function app. I have added a test value of type SQLServer as shown below.
- SQLServer:
SQLCONNSTR_
- MySQL:
MYSQLCONNSTR_
- SQLAzure:
SQLAZURECONNSTR_
- Custom:
CUSTOMCONNSTR_
- PostgreSQL:
POSTGRESQLCONNSTR_
- Notification Hub:
NOTIFICATIONHUBCONNSTR_
- Service Bus:
SERVICEBUSCONNSTR_
- Event Hub:
EVENTHUBCONNSTR_
- Document Db:
DOCDBCONNSTR_
- Redis Cache:
REDISCACHECONNSTR_
SQLCONNSTR_
is to be amended along with the connection string name.os.environ['SQLCONNSTR_test_sql_server_connectionString']
in code and able to get the expected value.