相关疑难解决方法(0)

在 Azure 中使用 GetEnvironmentVariable 读取 local.settings.json 中的 ConnectionStrings

在Azure函数v1local.settings.json中,我尝试使用GetEnvironmentVariable静态方法读取存在的连接字符串

这是我的local.settings.json文件

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
  },
  "ConnectionStrings": {
    "OnPremisesConnection": "Server=test;Initial Catalog=testdb;Integrated Security=SSPI;"
  }
}
Run Code Online (Sandbox Code Playgroud)

使用以下代码读取连接字符串

string variableName = "OnPremisesConnection";
var res = Environment.GetEnvironmentVariable($"ConnectionStrings:{variableName}")
Run Code Online (Sandbox Code Playgroud)

但我得到了NULL结果。我在这里缺少什么?

environment-variables azure azure-functions

5
推荐指数
1
解决办法
4999
查看次数

Azure 函数 - ConnectionString 属性尚未初始化

我在 Visual Studio 中开发了一个 Azure Function,并且在 Azure 中发布时它可以工作(从一年前开始)。

现在,我在 Visual Studio 中从该 Azure 函数制作了一个模板,并更改了一些细节,但基本上是相同的。当我在本地测试时,效果很好。

但是当我在 Azure 中发布它并尝试测试它时,我收到此错误:

The ConnectionString property has not been initialized
Run Code Online (Sandbox Code Playgroud)

我通常在应用程序设置中编写连接字符串(它适用于较旧的 Azure 功能)。

以下是该函数如何获取连接字符串的值:

var repo = new GranularRepository(ConfigurationManager.AppSettings["BoConnectionString"]);
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

var repo = new AvgDeliveryTime_GranularRepository(Environment.GetEnvironmentVariable("BodbConnectionString"));
Run Code Online (Sandbox Code Playgroud)

connection-string azure azure-functions

5
推荐指数
2
解决办法
7227
查看次数