Using Visual Studio 2017, I created a new Azure Function app. I added a function and one of the attribute parameters is ConnectionStringSetting
. That should be a reference to a setting stored somewhere, but I can't figure out where for the life of me.
When I try to debug the method, this is what I get back:
I have tried to put it in the local.settings.json
file, no luck. I have tried to add an app.config
/appSettings
section and that doesn't do anything, either.
I am not doing anything crazy in the method:
namespace MyFunctions
{
public static class TestUpdated
{
[FunctionName("DocumentUpdated")]
public static void Run(
[CosmosDBTrigger("mydb", "somecollection",
ConnectionStringSetting = "DbConnString",
LeaseCollectionName = "lease-test-trigger",
CreateLeaseCollectionIfNotExists = true)]
IReadOnlyList<Document> documents, TraceWriter log)
{
log.Info("Documents modified " + documents.Count);
log.Info("First document Id " + documents[0].Id);
}
}
}
All my extensions and nuget packages are on the latest versions.
So, how the heck do you set the connection string? It's been hours trying different things and nothing works.
In the code above, ConnectionStringSetting is the name of the setting that contains the connection string. In this case, it is CosmosDBConnection, so you would want to make sure that setting is properly set in your Functions configuration.
Both in-process and isolated process C# libraries use the CosmosDBTriggerAttribute to define the function. C# script instead uses a function.json configuration file. The name of an app setting or setting collection that specifies how to connect to the Azure Cosmos DB account being monitored. For more information, see Connections.
If multiple functions are configured to use a Cosmos DB trigger for the same collection, each of the functions should use a dedicated lease collection or specify a different LeaseCollectionPrefix for each function. Otherwise, only one of the functions will be triggered. For information about the prefix, see the Configuration section.
You can specify the MongoDB connection string using either: the DNS Seed List Connection Format. This section describes the standard format of the MongoDB connection URI used to connect to a MongoDB deployment: standalone, replica set, or a sharded cluster.
public static void Run(
[CosmosDBTrigger("mydb", "somecollection",
ConnectionStringSetting = "DbConnString",
LeaseCollectionName = "lease-test-trigger",
CreateLeaseCollectionIfNotExists = true)]
IReadOnlyList<Document> documents, TraceWriter log)
Per my experience , ConnectionStringSetting
should be set in App Settings.
The config would be:
{
"IsEncrypted": false,
"Values": {
"DbConnString": "...your cosmos db string..."
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With