[英]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:解决方案:
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.cs
行string 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
的环境变量,因此需要将其添加到函数配置中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.