Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core Azure WebJobs does not read from Azure Application Settings

I have an app service running with it's respective ConnectionString from Azure Portal. The ConnectionString is point to Azure SQL Server. Azure Portal Application Settings for Connection String

I have a WebJob with the following appsettings.json

{
  "ConnectionStrings": {
    "DefaultConnection": "Add your connection string"
  }
}

When I run the Web Job, it doesn't seem to pull the Connection strings from the azure portal, but it uses my default ConnectionStrings in appsettings.json.

[02/13/2017 08:45:27 > 2942c6: SYS INFO] Status changed to Initializing
[02/13/2017 08:45:27 > 2942c6: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[02/13/2017 08:45:27 > 2942c6: SYS INFO] Status changed to Running
[02/13/2017 08:45:27 > 2942c6: INFO] 
[02/13/2017 08:45:27 > 2942c6: INFO] D:\local\Temp\jobs\triggered\TestConnectionString\32vmiek4.2av>dotnet TestConnectionString.dll 
[02/13/2017 08:45:29 > 2942c6: INFO] Add your connection string
like image 627
Dawa Law Avatar asked Feb 13 '17 09:02

Dawa Law


People also ask

Is Azure WebJobs deprecated?

Azure WebJobs are deprecated, but still in use. They are being phased out in favor of Azure Functions. Azure Functions is a more up-to-date and feature rich service which offers a greater degree of flexibility and control.

Which Azure websites feature should you enable for continuously running WebJobs?

If you set the web app that hosts your job to run continuously, run on a schedule, or use event-driven triggers, enable the Always on setting on your web app's Azure Configuration page. The Always on setting helps to make sure that these kinds of WebJobs run reliably.

What is the difference between Azure functions and WebJobs?

Summary. Azure Functions offers more developer productivity than Azure App Service WebJobs does. It also offers more options for programming languages, development environments, Azure service integration, and pricing. For most scenarios, it's the best choice.


1 Answers

Make sure you call AddEnvironmentVariables() when building your configuration. e.g.

var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json")
    .AddEnvironmentVariables();
like image 57
David Ebbo Avatar answered Nov 03 '22 05:11

David Ebbo