简体   繁体   English

Azure Functions - 值不能为空。 (参数“连接字符串”)

[英]Azure Functions - Value cannot be null. (Parameter 'connectionString')

I was trying to setup simple Azure Function to read a XML stream and sync it back to the database.我试图设置简单的 Azure 函数来读取 XML 流并将其同步回数据库。 My plan was to use a Time Trigger to execute the function once per day.我的计划是使用时间触发器每天执行一次该功能。

Howerver, things are not looking great.然而,事情看起来并不好。 I'm getting the following error, even if I don't use a database:即使我不使用数据库,我也会收到以下错误:

[Error] Executed 'Functions.<func-name>' (Failed, Id=<func-id>, Duration=1ms)Value cannot be null. (Parameter 'connectionString')

I'm currently trying to execute the following function:我目前正在尝试执行以下功能:

module.exports = async function(context, req) {
    context.res = {
        body: "Success!"
    };
};

Same result.结果相同。 I can't run it.我无法运行它。

I've added a Connection String to the Configuration -> Connection Strings (I thought that I've missed that, based on the message).我已经在配置 - > 连接字符串中添加了一个连接字符串(根据消息,我认为我错过了它)。

My functions.json file looks like:我的 functions.json 文件如下所示:

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 * * * *"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

I've also tried running a C# function - same result.我也尝试过运行 C# 函数 - 结果相同。

So, what have I missed?那么,我错过了什么?

Logging from Microsoft to it's finest.从 Microsoft 登录到它是最好的。

AzureWebJobsStorage App Setting was missing.缺少 AzureWebJobsStorage 应用设置。

Solution:解决方案:

  1. Create Storage account (or use existing one)创建存储帐户(或使用现有的)
  2. Go to your Function App's Configuration转到您的函数应用程序的配置
  3. Add AzureWebJobsStorage with a connection string to your Storage account (can be found at Storage Account Overview -> Access Keys)将带有连接字符串的 AzureWebJobsStorage 添加到您的存储帐户(可以在存储帐户概述 -> 访问密钥中找到)

I was trying to setup simple Azure Function to read a XML stream and sync it back to the database.我试图设置简单的Azure函数以读取XML流并将其同步回数据库。 My plan was to use a Time Trigger to execute the function once per day.我的计划是每天使用一次时间触发器来执行该功能。

Howerver, things are not looking great.但是,情况看起来并不好。 I'm getting the following error, even if I don't use a database:即使不使用数据库,我也会遇到以下错误:

[Error] Executed 'Functions.<func-name>' (Failed, Id=<func-id>, Duration=1ms)Value cannot be null. (Parameter 'connectionString')

I'm currently trying to execute the following function:我目前正在尝试执行以下功能:

module.exports = async function(context, req) {
    context.res = {
        body: "Success!"
    };
};

Same result.结果相同。 I can't run it.我无法运行。

I've added a Connection String to the Configuration -> Connection Strings (I thought that I've missed that, based on the message).我已经在配置->连接字符串中添加了一个连接字符串(基于该消息,我认为我已经错过了)。

My functions.json file looks like:我的functions.json文件如下所示:

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 * * * *"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

I've also tried running a C# function - same result.我也尝试过运行C#函数-相同的结果。

So, what have I missed?那么,我错过了什么?

In my case the error was Microsoft.Extensions.Configuration.AzureAppConfiguration value cannot be null: parameter (connectionString)在我的情况下,错误是Microsoft.Extensions.Configuration.AzureAppConfiguration value cannot be null: parameter (connectionString)

This happened because I has installed Microsoft.Extensions.Configuration.AzureAppConfiguration in my Function to DI the configuration into my main function.发生这种情况是因为我在我的函数中安装了 Microsoft.Extensions.Configuration.AzureAppConfiguration 以将配置导入到我的主函数中。 The Startup.cs line string cs = Environment.GetEnvironmentVariable("MyDifferentConnectionString"); Startup.csstring cs = Environment.GetEnvironmentVariable("MyDifferentConnectionString"); was not able to find an environment variable for MyDifferentConnectionString , so this needed to be added to the Function config.无法找到MyDifferentConnectionString的环境变量,因此需要将其添加到函数配置中。

  1. Go to App Configuration (or create one)转到应用程序配置(或创建一个)
  2. Access Keys (under Settings)访问密钥(在设置下)
  3. Copy Connection String复制连接字符串
  4. Go to your Function转到您的功能
  5. Configuration (under Settings)配置(在设置下)
  6. Add a new Application Settings with the name of your environment variable and paste the value使用环境变量的名称添加新的应用程序设置并粘贴值
  7. Save and restart your Function保存并重新启动您的功能

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 azure CLI `func new` 给出错误`Value cannot be null. (Parameter 'value')` - azure CLI `func new` gives error `Value cannot be null. (Parameter 'value')` ReportViewer 15.0.0更新:Sys.ArgumentNullException:值不能为null。 参数名称:元素 - ReportViewer 15.0.0 Renerding: Sys.ArgumentNullException: Value cannot be null. Parameter name: element Autodesk 设计自动化“值不能为空。(参数‘ForgeConfiguration.ClientId’)” - Autodesk Design Automation "Value cannot be null. (Parameter 'ForgeConfiguration.ClientId')" 无法读取null的属性值。 onclick没有价值 - Cannot read property value of null. No value on onclick Azure Functions Http触发器-DocumentDB输出集成Microsoft.Azure.Documents.Client:值不能为null - Azure Functions Http trigger - DocumentDB out Integration Microsoft.Azure.Documents.Client: Value cannot be null 未捕获的类型错误:无法读取 null 的属性“样式”。 在同一页面中使用两个 Javascript 函数 - Uncaught TypeError: Cannot read property 'style' of null. Using two Javascript functions in the same page 使用 Azure Functions Core Tools 时如何解决“值不能为空”错误? - How to resolve 'Value cannot be null' error when using Azure Functions Core Tools? 无法读取null的属性&#39;appendChild&#39;。 Java脚本 - Cannot read property 'appendChild' of null. Javascript 无法读取 null 的属性。 循环中 - Cannot read properties of null. In loop 无法读取null的属性“ getElementsByTagName”。 无法弄清楚 - Cannot read property 'getElementsByTagName' of null. Cannot figure it out
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM