我有一个应用服务,它运行着来自Azure门户的相应ConnectionString。 ConnectionString指向Azure SQL Server。
我有一个带有以下appsettings.json的WebJob
{
"ConnectionStrings": {
"DefaultConnection": "Add your connection string"
}
}
当我运行Web作业时,它似乎不会从天蓝色门户中提取连接字符串,但它在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
答案 0 :(得分:6)
确保在构建配置时致电AddEnvironmentVariables()
。 e.g。
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();