Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
    • Data
Azure icon
Labs

Using Azure Cosmos DB with C#

In this lab, you will gain experience using C# and Visual Studio to connect to and use Cosmos DB. You will RDP into a Windows VM set up with Visual Studio and update a pre-built solution with the appropriate Cosmos DB C# code to connect to Cosmos DB, upload documents, and use the SQL API to query documents. When this is complete, you will run a console application to see everything working and can go back to the Azure portal to verify the documents were saved. Upon completion of the lab, you will have gained the experience required to work with Cosmos DB using C#.

Azure icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Sep 18, 2025
Duration
1h 0m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    RDP into the VM and open the Visual Studio solution.

    RDP login:

    See credentials in the credentials section of the lab window.
    

    PowerShell to run:

    $url = "https://github.com/ACloudGuru-Resources/content-azure-labs/blob/master/zips/Azure-LearningActivity-Cosmos%20DBv2.zip?raw=true"
    $zipfile = "C:\Users\cloud_user\Desktop\Azure-LearningActivity-Cosmos DBv2.zip"
    $folder = "C:\Users\cloud_user\Desktop"
    
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    Invoke-WebRequest -UseBasicParsing -OutFile $zipfile $url
    
    Expand-Archive -LiteralPath $zipfile -DestinationPath $folder
    
    Remove-Item -Path $zipfile
    
  2. Challenge

    Update the Visual Studio solution and run the console app.

    Create a New Container in the Azure Portal

    1. In the Azure portal, click All resources.
    2. Select the Azure Cosmos DB account resource in the list.
    3. Click Add Container.
    4. In the Add Container pane, set the following values:
      • Database id: Create new, and name it db1
      • Container id: collection1
      • Partition key: /Partition
      • Throughput: 400
    5. Click OK.

    Update the Visual Studio Code on VM

    1. Back on the virtual machine, in the Visual Studio window, double-click Program.cs in the right-hand menu to open it.
    2. In the Program class, we need to enter a couple pieces of missing information: EndpointUrl and PrimaryKey. In the Azure Portal, head to the Overview section for our Cosmos DB account.
    3. Copy the listed URI.
    4. Back in Visual Studio, paste it in as the EndpointUrl value.
    5. In the Azure portal, scroll down and click Keys (under the Settings heading).
    6. Copy the listed primary key.
    7. Back in Visual Studio, paste it in as the PrimaryKey value.
    8. Click the disk icon to save the code.
    9. Click the play button icon to run the console app.
    10. Back in the Azure portal, scroll down and click Document Explorer (under the Containers heading).
    11. Click Open Data Explorer.
    12. Click collection1.
    13. Click Documents. We should see two documents listed, which means we were successful.
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight