Unable to connect to Azure Cosmos Db Account (Core SQL API) using EF Core 3.0 CosmosDb provider

.net-core-3.0 azure-cosmosdb azure-cosmosdb-sqlapi entity-framework-core entity-framework-core-3.0

Question

I'm unable to connect to an Azure CosmosDB with the CosmosDb provider using the following packages:

Microsoft.EntityFrameworkCore 3.0.0 Microsoft.EntityFrameworkCore.Cosmos 3.0.0

Getting this message back:

Response status code does not indicate success: 503 Substatus: 0 Reason: (The request failed because the client was unable to establish connections to 3 endpoints across 1 regions. Please check for client resource starvation issues and verify connectivity between client and server.

Stacktrace

at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode() at Microsoft.Azure.Cosmos.CosmosResponseFactory.ToObjectInternal[T](ResponseMessage cosmosResponseMessage, CosmosSerializer jsonSerializer) 
at Microsoft.Azure.Cosmos.CosmosResponseFactory.<>c__DisplayClass6_0.<CreateDatabaseResponseAsync>b__0(ResponseMessage cosmosResponseMessage) 
at Microsoft.Azure.Cosmos.CosmosResponseFactory.<ProcessMessageAsync>d__121.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.Azure.Cosmos.CosmosClient.<CreateDatabaseIfNotExistsAsync>d__40.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.d__13.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.CreateDatabaseIfNotExistsOnce(DbContext context, Object state) 
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func3 operation, Func3 verifySucceeded, TState state) 
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) 
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.CreateDatabaseIfNotExists() at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosDatabaseCreator.EnsureCreated() 
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated() at EFCoreCosmosDbTest.Test.<Run>d__0.MoveNext() in C:\Git\EFCoreCosmosDbTest\EFCoreCosmosDbTest\Test.cs:line 26 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at EFCoreCosmosDbTest.Program.<Main>d__0.MoveNext()
in C:\Git\EFCoreCosmosDbTest\EFCoreCosmosDbTest\Program.cs:line 9

If I change to the Microsoft.Azure.DocumentDB.Core 2.8.1 and use the DocumentClient I have no issues connecting to the same CosmosDb account in Azure and create my database, container etc. from the same solution.

Also, if I download the .net core quickstart project from Azure, it works without issues.

Note, that It works fine connecting to a the Azure Cosmos Db Emulator locally with EF.

I used the https://github.com/aspnet/EntityFramework.Docs/tree/master/samples/core/Cosmos repo to run the test.

Any ideas what I'm doing wrong?

  • EF Core version: 3.0
  • Database provider: Microsoft.EntityFrameworkCore.CosmosDb
  • Target framework: .NET Core 3.0
1
0
10/18/2019 8:40:44 AM

Popular Answer

The EF Provider is using the Cosmos SDK package underneath.

enter image description here

Please add the Microsoft.Azure.Cosmos package to your project targeting the latest version (3.2.2).

You can do this through the NET Core CLI by running dotnet add package Microsoft.Azure.Cosmos on the folder with your current project files, and it should update your CSPROJ with the PackageReference.

0
10/18/2019 2:37:48 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow