Kenny_I
Kenny_I

Reputation: 2513

Unable to resolve the value for property 'CosmosDBAttribute.ConnectionStringSetting'

I have developed simple Service Bus Trigger with CosmosDB Output with Visual Studio. Connection strings of Service Bus and CosmosDB are defined in local.settings.json. Code is fully function locally. Now I have Zip Published Function(C#) to Azure.

I'm getting Error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. 
Microsoft.Azure.WebJobs.Host: Unable to resolve the value for property 
'CosmosDBAttribute.ConnectionStringSetting'. 

What should I do?

enter image description here

Upvotes: 5

Views: 9476

Answers (3)

Anton
Anton

Reputation: 53

In my the extension was missing in host.json:

{
    "version": "2.0",
    "extensions": {
        "cosmosDB": {
            "connectionMode": "Gateway",
            "protocol": "Https",
            "leaseOptions": {
                "leasePrefix": "prefix1"
            }
        }
    }
}

Here the reference: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-output?tabs=csharp#hostjson-settings

Upvotes: 0

Karthikeyan VK
Karthikeyan VK

Reputation: 6026

I had the same issue in local when running the azure function. My connection string was not accepted because the AccountKey was considered part of the URL of AccountEndpoint, and I gave space between the endpoint of AccountKey and AccountEndpoint.

"connectionStringSetting": "AccountEndpoint=; AccountKey=;"

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "myCosmosDb": "AccountEndpoint=https://mycosmoscosmosdb.documents.azure.com:443/; AccountKey=asd4ph1omRg9Rn4dlj7h1f7XqUdO1mHJcpG9rN1XECSO4P6LKorDXjdqK8VTookKvbKXjPTulpEsdfdsbwg==;"
  }
}

Upvotes: 3

suziki
suziki

Reputation: 14103

The error tells you need to add the settings on Azure.

azure function on azure is different from azure functions on local. on local the settings is in the local.settings.json. But on azure it is in the Configuration.(Even if you deploy the local.settings.json, the function will read env settings from Congfiguration)

enter image description here

enter image description here

And dont forget to save your edit.

Upvotes: 7

Related Questions