Azure functions are very practical and unexpensive. You can have your own serverless function in a matter of minutes, check them out if you haven’t yet.
Getting in context
Today I was running into an issue working with an Azure Function. The AZF had to connect to an SQL server database. To handle connection strings the best practice is to parametrize them using config files for local development and using the configuration tab in azure once published.
You should be able to access the value by calling the System.Environment.GetEnvironmentVariable method, passing the key you want to get. But, for some reason, I wasn’t able to get the connection string from the settings. It worked in my machine but it didn’t work on azure.
I did some googling around and I found this Github issue thread. In it I found my answer. I’m leaving the code bellow:
As it turns out, Azure has a specific convention for naming connection strings sets from the Azure Function configuration. The convention depends on the Database engine the connection is aiming.
From what I gathered this is the convention, the name of the connection string key will start with one of these depending on the type of DB specified:
- MySQL: MYSQLCONNSTR_
- SQLServer: SQLCONNSTR_
- SQLAzure: SQLAZURECONNSTR_
- Custom Connection : CUSTOMCONNSTR_
In short I would recommend one of two approaches from now on, either copy the functions from the solution or rename your connection string key names in your local settings file to match the Azure configuration convention.
That’s all folks, have a good one!