【问题标题】:Attempting to connect to azure database has suddenly stopped working, throwing exceptions尝试连接天蓝色数据库突然停止工作,抛出异常
【发布时间】:2018-11-06 18:59:00
【问题描述】:

我在 Azure Function (V2) 中运行以下代码;

 new DocumentClient(new Uri(keys.dbEndPoint), keys.dbPrimaryKey);

直到今天,它在 localhost 上的 azure 函数中运行良好,没有改变任何东西我现在得到以下异常:

数据 [IDictionary]:{System.Collections.ListDictionaryInternal} HResult [int]:-2146233036 HelpLink [string]:null InnerException [异常]:{System.NullReferenceException:未设置对象引用 到一个对象的实例。} Message [string]:"类型初始化器 对于“Microsoft.Azure.Documents.UserAgentContainer”抛出了一个 异常。" 源 [字符串]:"Microsoft.Azure.DocumentDB.Core" StackTrace [字符串]:”在 Microsoft.Azure.Documents.UserAgentContainer..ctor()\r\n at Microsoft.Azure.Documents.Client.ConnectionPolicy..ctor()\r\n at Microsoft.Azure.Documents.Client.ConnectionPolicy.get_Default()\r\n
在 Microsoft.Azure.Documents.Client.DocumentClient.Initialize(Uri serviceEndpoint, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel)\r\n at Microsoft.Azure.Documents.Client.DocumentClient..ctor(Uri serviceEndpoint, String authKeyOrResourceToken, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel)\r\n at Platform.AzureConfig.get_Database() 在 D:\DeansClo​​ud\AzureConfig.cs:line 60" TargetSite [MethodBase]:{Void .ctor()} 类型名称 [string]:"Microsoft.Azure.Documents.UserAgentContainer" 静态成员 非公众成员

话不多说,内部异常提到了空引用异常:

消息[字符串]:“对象引用未设置为对象的实例。”

这是 azure cosmos db 现在的问题吗?我需要更新一些东西吗?

【问题讨论】:

  • 您使用的是哪个 Functions 版本? v1 还是 v2?另外,您能否添加更多代码来如何在函数中实例化 DocumentClient?通过绑定还是手动?
  • @silent V2 和手动

标签: c# azure azure-functions azure-cosmosdb


【解决方案1】:

我发现问题出在最新的 azure core 工具上,降级到版本 24 解决了这个问题。

【讨论】:

    【解决方案2】:

    尝试使用基于绑定的版本,而不是创建自己的 DocumentClient。这也将为您提供更好的性能。查看示例 herehere

    【讨论】:

      猜你喜欢
      • 2021-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2016-07-18
      • 1970-01-01
      相关资源
      最近更新 更多