6

我有一个应用服务运行它来自 Azure 门户的相应 ConnectionString。ConnectionString 指向 Azure SQL Server。 连接字符串的 Azure 门户应用程序设置

我有一个带有以下 appsettings.json 的 WebJob

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

当我运行 Web 作业时,它似乎没有从 azure 门户中提取连接字符串,但它使用了我在 appsettings.json 中的默认 ConnectionStrings。

[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
4

1 回答 1

6

确保AddEnvironmentVariables()在构建配置时调用。例如

var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json")
    .AddEnvironmentVariables();
于 2017-02-14T02:32:58.690 回答