CosmosDBTrigger:在哪里指定连接字符串? [英] CosmosDBTrigger: Where to specify connection string?

查看:126
本文介绍了CosmosDBTrigger:在哪里指定连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio 2017,我创建了一个新的Azure Function应用.我添加了一个函数,属性参数之一是ConnectionStringSetting.那应该是对存储在某处的设置的引用,但是我无法弄清楚我一生的位置.

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:

我试图将其放在local.settings.json文件中,但不走运.我试图添加app.config/appSettings部分,但这也没有任何作用.

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);
        }
    }
}

我所有的扩展程序和nuget软件包都在最新版本上.

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.

推荐答案

public static void Run(
[CosmosDBTrigger("mydb", "somecollection",
ConnectionStringSetting = "DbConnString",
LeaseCollectionName = "lease-test-trigger",
CreateLeaseCollectionIfNotExists = true)]
IReadOnlyList<Document> documents, TraceWriter log)

根据我的经验,应在应用程序设置"中设置ConnectionStringSetting.

Per my experience , ConnectionStringSetting should be set in App Settings.

配置为:

{
    "IsEncrypted": false,
    "Values": {
        "DbConnString": "...your cosmos db string..."
    }
}

这篇关于CosmosDBTrigger:在哪里指定连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆