locked
Microsoft.Azure.Cosmos.CosmosException RRS feed

  • Question

  • Hi , I am not able to fix below Issue i am trying to connect cosmos Db to Asp.net core Mvc Application while debugging i got this issue in configure service i am sharing my code and please have look into attched screen shot

    Step 1

    public void ConfigureServices(IServiceCollection services)
            {
                services.AddControllersWithViews();
                services.AddSingleton<ICosmosDBService>(InitializeCosmosClientInstanceAsync(Configuration.GetSection("CosmosDb")).GetAwaiter().GetResult());
            }

    Step 2

    private static async Task<CosmosDBService> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
            {
                string databaseName = configurationSection.GetSection("DatabaseName").Value;
                string containerName = configurationSection.GetSection("ContainerName").Value;
                string account = configurationSection.GetSection("Account").Value;
                string key = configurationSection.GetSection("Key").Value;
                Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key);
                Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder
                                    .WithConnectionModeDirect()
                                    .Build();
                CosmosDBService cosmosDbService = new CosmosDBService(client, databaseName, containerName);
                Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);
                await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

                return cosmosDbService;
            }

    Exception :

    Microsoft.Azure.Cosmos.CosmosException: 'Response status code does not indicate success: 400 Substatus: 0 Reason: (Exception of type 'Microsoft.Azure.Documents.DocumentClientException' was thrown., Windows/10.0.18362 cosmos-netstandard-sdk/3.3.0).

    Saturday, May 23, 2020 4:44 PM

All replies

  • Hello Yogesh,

    Let me repro this and come back to you

    Tuesday, May 26, 2020 1:13 PM