CosmosDBTrigger: Where to specify connection string?

一个人想着一个人 提交于 2019-12-23 09:06:48

问题


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

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