Connect to CosmosDB

Gerardo Canio 0 Reputation points
2023-05-25T13:28:42.7966667+00:00

I am trying to connect and save/retrieve data to Azure Cosmos DB. I have referred to the Azure Documentation but am still

having difficulties. I am using Windows 10 and using the following code snippet. Please provide any help!

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,901 questions
{count} votes

1 answer

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 29,542 Reputation points Microsoft Employee Moderator
    2023-05-30T15:14:57.47+00:00

    @Gerardo Canio Please share your code snippet to better assist you or here is the sample code Azure Cosmos DB using the NoSQL API and perform basic data operations which can try and don't forget to replace with your cosmos DB connection string.

    using System;
    
    using System.Threading.Tasks;
    
    using Microsoft.Azure.Cosmos;
    
    
    
    class Program
    
    {
    
        private static readonly string connectionString = "your_cosmosdb_connection_string";
    
        private static readonly string databaseId = "your_database_name";
    
        private static readonly string containerId = "your_container_name";
    
    
    
        static async Task Main(string[] args)
    
        {
    
            CosmosClient cosmosClient = new CosmosClient(connectionString);
    
            Database database = await cosmosClient.CreateDatabaseIfNotExistsAsync(databaseId);
    
            Container container = await database.CreateContainerIfNotExistsAsync(containerId, "/partitionKey");
    
    
    
            // Rest of the code remains the same as in the previous example
    
            // ...
    
    
    
        }
    
    }
    
    
    

    Regards

    Geetha

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.