I'm trying to configure an Azure WebJob with my .NET Core project. Every time I execute the job in Azure, it tells me the error:
Make sure that you are setting a connection string named AzureWebJobsDashboard in your Microsoft Azure Website configuration by using the following format DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY pointing to the Microsoft Azure Storage account where the Microsoft Azure WebJobs Runtime logs are stored.
Here's my code where I'm configuring everything, as well as the config stuff:
private static void ConfigureServices(IServiceCollection serviceCollection)
{
// Optional: Setup your configuration:
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
// add any interfaces that will be needed here
serviceCollection.AddScoped<IBatchJobService, BatchJobService>();
// executes the job
serviceCollection.AddScoped<ExecuteBatchJobs, ExecuteBatchJobs>();
// One more thing - tell azure where your azure connection strings are
var connStringDashboard = configuration["ConnectionStrings:AzureWebJobsDashboard"];
var connStringStorage = configuration["ConnectionStrings:AzureWebJobsStorage"];
Environment.SetEnvironmentVariable("AzureWebJobsDashboard", connStringDashboard);
Environment.SetEnvironmentVariable("AzureWebJobsStorage", connStringStorage);
}
And here's the appsettings.json file:
{
"ConnectionStrings": {
"AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=xxxxxxxxxxx;AccountKey=mykey;",
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=xxxxxxxxxxx;AccountKey=mykey;"
}
}
I've set a breakpoint in my code locally on the "var connStringDashboard = ....", and it CORRECTLY reads in the values from the appsettings.json.
Then after that it sets the connection strings via environment variables.
Any thoughts on where I'm going wrong on setting up the connection strings? It seems like Azure's not able to read them from the environment variables for some reason.