【问题标题】:Azure Cosmos DB Quickstart example not workingAzure Cosmos DB 快速入门示例不起作用
【发布时间】:2018-06-18 13:01:39
【问题描述】:

我创建了一个新的 Azure CosmosDB (Gremlin API),然后下载了快速入门示例:

当我运行它时,会出现这个异常:

JsonReaderException:从 JsonReader 读取 JObject 时出错。路径'',第 0 行,第 0 位置。

我检查了,endpoint 和 authKey 都设置好了。

    public async Task RunAsync(DocumentClient client)
    {
        // the line below throws the Exception
        Database database = await client.CreateDatabaseIfNotExistsAsync(new Database { Id = "graphdb" });

        DocumentCollection graph = await client.CreateDocumentCollectionIfNotExistsAsync(
            UriFactory.CreateDatabaseUri("graphdb"),
            new DocumentCollection { Id = "Persons" },
            new RequestOptions { OfferThroughput = 1000 });

Quickstard 示例附带在 App.config 文件中填写的端点和 authKey:

如何解决?

【问题讨论】:

  • 这不是引发异常的实际代码行。尝试在 RunAsync 方法的开头放置一个断点,看看哪一行抛出了错误
  • 好的,我放了断点,异常发生在 Database database = await client.CreateDatabaseIfNotExistsAsync(new Database { Id = "graphdb" });
  • 试试var database = await client.CreateDatabaseIfNotExistsAsync(new Database { Id = "graphdb" });...你能告诉我们DocumentClient的定义吗?
  • 试过 var 数据库,它是 ResourceResponse,得到了同样的异常 // DocumentClient 来自 Microsoft.Azure.Documents.Client 程序集
  • 但是您需要在某处设置客户端,并且向该客户端传递您的 azure cosmosdb 凭据...如果没有这一步,您将无法执行任何操作。

标签: c# azure-cosmosdb gremlin


【解决方案1】:

请将端点改成https://<account-name>.documents.azure.com:443/这种格式。

这是新创建的 Gremlin 帐户当前存在的问题,很快将在快速入门中解决。

【讨论】:

猜你喜欢
  • 2021-01-20
  • 1970-01-01
  • 1970-01-01
  • 2021-06-06
  • 1970-01-01
  • 2018-11-15
  • 1970-01-01
  • 2017-02-04
  • 1970-01-01
相关资源
最近更新 更多