Dawa Law
Dawa Law

Reputation: 128

.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

Upvotes: 6

Views: 1028

Answers (1)

David Ebbo
David Ebbo

Reputation: 43183

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

var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json")
    .AddEnvironmentVariables();

Upvotes: 6

Related Questions