问题
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.
回答1:
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..."
}
}
来源:https://stackoverflow.com/questions/47625959/cosmosdbtrigger-where-to-specify-connection-string