skip to Main Content

In the example I found, you need to setx AZURE_STORAGE_CONNECTION_STRING for a real environment variable. But Azure function does not have that, only configuration.
I set it in the local.settings.json file but when I run it has an issue with it and the function does not load.

How do I get the connection string to work?

[2023-09-12T11:14:30.192Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ContractQueue'. System.Private.CoreLib: Exception has been thrown by the target of an invocation. Azure.Storage.Queues: No valid combination of account information found.
[2023-09-12T11:14:30.214Z] Error indexing method 'Functions.ContractQueue'
[2023-09-12T11:14:30.218Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ContractQueue'. System.Private.CoreLib: Exception has been thrown by the target of an invocation. Azure.Storage.Queues: No valid combination of account information found.
[2023-09-12T11:14:30.222Z] Function 'Functions.ContractQueue' failed indexing and will be disabled.
[2023-09-12T11:14:30.294Z] The 'ContractQueue' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ContractQueue'. System.Private.CoreLib: Exception has been thrown by the target of an invocation. Azure.Storage.Queues: No valid combination of account information found.

2

Answers


  1. Chosen as BEST ANSWER

    "AzureWebJobsAzureWebJobsStorage": "UseDevelopmentStorage=true", must be in the in the settings


  2. Addition to my comment, while creating the azure queue triggered function you will get below options in the function template due to the below item

    enter image description here

    If configuration dependencies is ticked, then you will prompted to the following options in next step

    enter image description here

    For first two options, you will need to give the connection string as below in your local settings file and in function.cs file and this will use local storage queue emulator.

    local.settings

    {
        "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
      }
    }
    

    function.cs

    [Function(nameof(Function1))]
            public void Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] QueueMessage message)
            {
                _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}");
            }
    

    But if you will choose Azure Storage option, then it will show you all the storage account in your subscription. Select one of the storage account and provide the connection string name as below

    enter image description here

    Function.cs file will look like below

    [Function(nameof(Function1))]
            public void Run([QueueTrigger("input-queue", Connection = "AZURE_STORAGE_CONNECTION_STRING")] QueueMessage message)
            {
                _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}");
            }
    

    No need to add AZURE_STORAGE_CONNECTION_STRING in your local settings file because its already stored in secrets.json file.

    enter image description here

    Output:

    enter image description here

    Please Note: You need to use latest package of Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues and Azure.Storage.Queues

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search