3
votes

When creating a new WebJob project, the AzureWebJobsStorage connection string is added to App.config > configuration > connectionStrings

In contrast, the microsoft documentation for storage account connection strings clearly states AppSettings is where they'd put it.

What is the recommended place? Is connectionStrings only for database connection strings?

We will consume the connection string in an Azure Web App

1
App settings makes it easier for you to over write it in your build process within VSTS or within Azure as it's a simple over write, however with connection strings it gets a bit more complex. Seperate connection string files are also good, but if you are looking for a secure storage location than Azure Key Vault is a good option.ObiEff
Using KeyVault moves the question to, "when in dev", but there you could still ask the same question.Michiel Cornille
Im not so much interested in why app settings over connection strings, I'm interested in what is the consensus "imposed" by MS, .. but with the downvotes Im afraid this will get buried soon, thanks anyway @ObiEffMichiel Cornille
Apologies, I thought it was more of a when would you use what. AFAIK there isn't really a convention, different methods serve different purposes. Some of the examples Microsoft provide use the Connection Strings file,some use app settings. With regards to KeyVault there are two approaches to use, you could have multiple keyVaultInstances, one for each environment. Another solution is to have a wrapper around the KeyVaultClient that appends the environment name onto the key so dbConnectionString -> dbConnectionStringDev. The environment name would be stored in the appSettings.ObiEff

1 Answers

5
votes

When creating a new WebJob project, the AzureWebJobsStorage connection string is added to App.config > configuration > connectionStrings

When your creating the Azure WebJob project, it would reference the related WebJob libraries (Microsoft.Azure.WebJobs, Microsoft.Azure.WebJobs.Core). You need to specify a storage account for the WebJob SDK to log traces and metric data. And the connection string need to be specified under the connectionStrings section of your config file, otherwise you would retrieve the following error:

Microsoft Azure WebJobs SDK Dashboard connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:

  1. Set the connection string named 'AzureWebJobsDashboard' in the connectionStrings section of the .config file in the following format

  2. Set the environment variable named 'AzureWebJobsDashboard'

  3. Set corresponding property of JobHostConfiguration

Per my understanding, the Azure WebJob SDK only support reading the storage connection string from the above approaches. You could also set the connection string under the appSettings section, at this point you need to specify the related properties when constructing the JobHostConfiguration as follows:

static void Main()
{
    var config = new JobHostConfiguration()
    {
        DashboardConnectionString= ConfigurationManager.AppSettings["AzureWebJobsDashboard"],
        StorageConnectionString= ConfigurationManager.AppSettings["AzureWebJobsStorage"]
    };

    if (config.IsDevelopment)
    {
        config.UseDevelopmentSettings();
    }

    var host = new JobHost(config);
    // The following code ensures that the WebJob will be running continuously
    host.RunAndBlock();
}

Moreover, you could Use the Azure storage emulator for development and testing. While for production, you could specify the related app settings or connection strings on Azure Portal for overriding your dev settings. More details, you could refer to here for a better understanding of it.

What is the recommended place? Is connectionStrings only for database connection strings?

Per my understanding, when you are using the 3rd party libraries, you need to follow it's instruction for configuration. While you writing your code, you could define the connection string as you wish and read them in the corresponding way.