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

邮差的信 提交于 2021-01-29 05:43:41

问题


I was trying to setup simple Azure Function to read a XML stream and sync it back to the database. 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:

{
  "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.

So, what have I missed?


回答1:


Logging from Microsoft to it's finest.

AzureWebJobsStorage App Setting was missing.

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)



回答2:


From the call stack in your post, I think error is for the connection string not set.

The local.settings.json file stores app settings, connection strings, and settings used by local development tools. Settings in the local.settings.json file are used only when you're running projects locally.

By default, these settings are not migrated automatically when the project is published to Azure. Use the --publish-local-settings switch when you publish to make sure these settings are added to the function app in Azure. Note that values in ConnectionStrings are never published.

App settings in a function app contain global configuration options that affect all functions for that function app. When you run locally, these settings are accessed as local environment variables.

Make sure you have added a relevant App setting for ConnectionString in the Portal App settings blade.



来源:https://stackoverflow.com/questions/64844897/azure-functions-value-cannot-be-null-parameter-connectionstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!