Azure Cosmos DB - CreateDatabaseAsync - 未找到资源

时间:2017-10-23 04:18:02

标签: c# azure asp.net-web-api azure-cosmosdb asp.net-core-2.0

我一直在使用模拟器使用Azure Cosmos DB开发应用程序并取得了很大的成功 - 我已经能够创建数据库&集合并将文档添加到集合中以及读取这些文档。现在的麻烦是我尝试将模拟器换成Azure Cosmos DB的实时实例,并且在尝试创建数据库时遇到错误。

Microsoft.Azure.Documents.DocumentClientException: Entity with the specified id does not exist in the system.

请注意,这是在尝试创建数据库时找不到它,具体代码如下

public async Task CreateDatabaseIfNotExistsAsync()
    {
        try
        {
            await client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(_databaseId));
        }
        catch (DocumentClientException e)
        {
            if (e.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                await client.CreateDatabaseAsync(new Database { Id = _databaseId }); // Throws Not Found Here!
            }
            else
            {
                Console.Write(e.StatusCode);
                Console.ReadKey();
            }
        }
    }

非常感谢任何帮助。

修改

  • 我没有连接字符串,只有端点和访问密钥 - 我正在与

    连接

    client = new DocumentClient(new Uri(_endpoint),_ key);

  • 我的目标是DocumentDB API

  • UriFactory.CreateDatabaseUri(_databaseId)的输出是dbs / digivate_clients_0_blogging
  • 下面的完整例外内容

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware [0]       执行请求时发生了未处理的异常 Microsoft.Azure.Documents.DocumentClientException:系统中不存在具有指定标识的实体。 ActivityId:8df27b98-ed3b-4aed-ac9a-cfb0e6374aa4    在Microsoft.Azure.Documents.Client.ClientExtensions.d__1.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() at Microsoft.Azure.Documents.Client.GatewayServiceConfigurationReader.<GetDatabaseAccountAsync>d__41.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()    在Microsoft.Azure.Documents.Routing.GlobalEndpointManager.d__18.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() at Microsoft.Azure.Documents.Client.GatewayServiceConfigurationReader.<InitializeReaderAsync>d__43.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()    在Microsoft.Azure.Documents.Client.DocumentClient.d__267.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.Azure.Documents.Client.DocumentClient.d__55.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.Azure.Documents.Client.DocumentClient.d__100.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.Azure.Documents.Client.DocumentClient.d__104.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() at Microsoft.Azure.Documents.BackoffRetryUtility 1.&lt;&gt; c__DisplayClass1_0。&lt; b__0&gt; d.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() at Microsoft.Azure.Documents.BackoffRetryUtility 1.d__3.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在Microsoft.Azure.Documents.BackoffRetryUtility 1.<ExecuteRetry>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()    在Microsoft.Azure.Documents.BackoffRetryUtility 1.<ExecuteAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()    在Digivate.Blogging.DocumentDb.DocumentDBRepository 1.<CreateDatabaseIfNotExistsAsync>d__11.MoveNext() in I:\Digivate.Blogging\Digivate.Blogging.DocumentDb\DocumentDBRepository.cs:line 94 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Digivate.Blogging.API.Controllers.PublishedBlogPostsController.<_canLoadDocuments>d__6.MoveNext() in I:\Digivate.Blogging\Digivate.Blogging.Api\Controllers\PublishedBlogPostsController.cs:line 154 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()    在Digivate.Blogging.API.Controllers.PublishedBlogPostsController.d__1.MoveNext()在I:\ Digivate.Blogging \ Digivate.Blogging.Api \ Controllers \ PublishedBlogPostsController.cs:第25行 ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在lambda_method(Closure,Object)    在Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__10.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next,Scope&amp; scope,Object&amp; state,Boolean&amp; isCompleted)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__22.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State&amp; next,Scope&amp; scope,Object&amp; state,Boolean&amp; isCompleted)    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__17.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__15.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.d__6.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.d__7.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()

感谢

0 个答案:

没有答案