Azure Function 无法连接到 Cosmos DB

标签 azure azure-functions azure-cosmosdb

尝试运行我的 Azure 函数时,应用程序洞察中不断出现错误,它在我的计算机本地运行,但在 Azure 中不起作用。这是错误消息:

System.InvalidOperationException at Microsoft.Azure.WebJobs.Extensions.CosmosDB.CosmosDBTriggerAttributeBindingProvider.ResolveConnectionString

我在设置配置中添加了 CosmosDbTrigger 作为连接字符串,所以我不明白出了什么问题。当在 cosmos 数据库中进行更改时会触发该函数,因此如果我更改了数据库中的某些内容,并且在我的电脑上本地运行该函数,它就可以工作,只有在 azure 门户中它才会不断失败。触发器也可以工作,所以我认为这只是功能的问题。

最佳答案

由于此 link 中还有许多其他类似问题的讨论并检查这个 link并尝试重新检查您的配置文件。

internal string ResolveConnectionString(string unresolvedConnectionString, string propertyName)
{
    // First, resolve the string.
    if (!string.IsNullOrEmpty(unresolvedConnectionString))
    {
        string resolvedString = _configuration.GetConnectionStringOrSetting(unresolvedConnectionString);

        if (string.IsNullOrEmpty(resolvedString))
        {
            throw new InvalidOperationException($"Unable to resolve app setting for property '{nameof(CosmosDBTriggerAttribute)}.{propertyName}'. Make sure the app setting exists and has a valid value.");
        }

        return resolvedString;
    }

    // If that didn't exist, fall back to options.
    return _options.ConnectionString;
}

此外,请检查您的 _options.ConnectionString 值并动态设置。

builder.Services.PostConfigure<CosmosDBOptions>(options =>
{
    options.ConnectionString = "dynamically set the connection string value here";
});

关于Azure Function 无法连接到 Cosmos DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71955554/

相关文章:

python - 如何在 Azure Cloud Shell 中安装 python 3.6

azure - 从 LogicApp 中的 json 获取值

Azure Functions、功能键无法访问并且门户中的文件看起来丢失

c# - Azure Cosmos/Document DB ResourceResponse<Document> 使用反射错误进行单元测试

azure-cosmosdb - Azure cosmos db - WHERE 子句返回的文档的默认顺序

azure - documentdb 中的冲突解决

azure - 用于查询 azure SQL 数据的移动服务 API 或 .net Web API

visual-studio - 在 Visual Studio 中进行本地调试时,是否有一种方法可以轻松地仅允许运行 azure 函数的子集?

azure - 在 Azure Function 中访问 Azure Key Vault secret

具有触发计时器的 Azure Functions 不会在监视器下显示日志