简体   繁体   English

通过 Visual Studio 创建 Azure function 时无法连接到 Cosmos DB

[英]Unable to connect to Cosmos DB while creating Azure function through Visual Studio

I am new to both Azure Functions and Cosmos DB.我是 Azure 函数和 Cosmos DB 的新手。 I am trying to set up an Azure function in my local machine that gets triggered on updates on Cosmos DB through Visual Studio.我正在尝试在我的本地计算机上设置一个 Azure function,它会在通过 Visual Studio 更新 Cosmos DB 时触发。

Initially, I was getting the error Unable to resolve app setting for property CosmosDBTriggerAttribute.ConnectionStringSetting but on following this solution I am able to resolve that error, but now getting:最初,我收到错误Unable to resolve app setting for property CosmosDBTriggerAttribute.ConnectionStringSetting但按照此解决方案,我能够解决该错误,但现在得到:

The listener for function 'Function1' was unable to start. System.Net.Http: No such host is known. System.Private.CoreLib: No such host is known.

Here are my local.settings.json :这是我的local.settings.json

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "connectionString": "AccountEndpoint=https://<collectionName>.documents.azure.com:443/;AccountKey=<key>"
  }
}

This is my run method if useful:如果有用,这是我的运行方法:

public static void Run([CosmosDBTrigger(
            databaseName: "DB-Name",
            collectionName: "CollectionName",
            ConnectionStringSetting = "String I used while setting up the project in VS",
            LeaseCollectionName = "leases")]IReadOnlyList<Document> input, ILogger log)
        {
            if (input != null && input.Count > 0)
            {
                log.LogInformation("Documents modified " + input.Count);
                log.LogInformation("First document Id " + input[0].Id);
            }
        }

Can someone help?有人可以帮忙吗? My other question is what is Account Key in this case?我的另一个问题是在这种情况下Account Key是什么? I am currently using the app name in my Cosmos DB account.我目前在我的 Cosmos DB 帐户中使用该应用程序名称。

You can find the AccountKey from Settings -> ConnectionString -> Primary Password when you click on your cosmosDB resource单击cosmosDB resource时,您可以从Settings -> ConnectionString -> Primary Password找到 AccountKey

and also your connectionString should be something like below,而且您的 connectionString 应该如下所示,

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "CosmosDB": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure Function V4 Do.net隔离无法连接cosmos db - Azure Function V4 Dotnet Isolated unable to connect to cosmos db Azure Cosmos DB 数据迁移工具无法连接到 Cosmos DB - Azure Cosmos DB Data Migration Tool unable to connect to Cosmos DB Azure Function 没有连接到 Cosmos DB - Azure Function does not connect to Cosmos DB 无法从 Azure Function 连接到 Azure Cosmos DB。 获取“Microsoft.Azure.Cosmos.Direct:Object 引用未设置为 object 的实例 - Unable to Connect from Azure Function to Azure Cosmos DB. Getting "Microsoft.Azure.Cosmos.Direct: Object reference not set to an instance of an object Azure Cosmos DB - 创建容器时出现“RequestDisallowedByPolicy”错误 - Azure Cosmos DB - 'RequestDisallowedByPolicy' error while creating container Mongoshell无法连接到Cosmos DB - Mongoshell unable to connect to Cosmos DB 有没有办法将Cosmos DB预触发连接到Azure函数或WebJob? - Is there a way to connect Cosmos DB pre-trigger to an Azure function or WebJob? 无法使用 Microsoft.EntityFrameworkCore.Cosmos 连接到 Azure Cosmos Db 帐户 - 响应状态代码 - Unable to connect to Azure Cosmos Db Account using Microsoft.EntityFrameworkCore.Cosmos - Response status code 从Visual Studio 2013创建Azure项目时无法使用Windows Azure帐户登录 - Unable to sign in using my Windows Azure account while creating an Azure project from Visual Studio 2013 CqlSession 无法连接到 Azure Cosmos DB Cassandra - CqlSession cannot connect to Azure Cosmos DB Cassandra
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM