Hi @Divya Ravindran,
Thanks for the question and using MS Q&A platform.
I tested the same code you're using, and it worked perfectly on my end. Could you please try the following steps and see if it works for you too?
First make sure that your Cosmos DB Emulator is running.
- It should be run inhttps://localhost:8081/_explorer/index.html in your browser.
- Create a .NET Console Application using Visual Studio.
- Install the Azure Cosmos DB SDK.
Open the NuGet Package Manager (right-click on the project in Solution Explorer, then select "Manage NuGet Packages"). Search for Microsoft.Azure.Cosmos and install it.
Paste your code in program.cs and click on "start" button to build and run your application.
You will not find any issues and the database is created.
Now, Open the Cosmos DB Emulator and you can find the Data Base there.
If the issue still persists, please check the following:
Step1: Ensure the emulator is running by visiting https://localhost:8081/_explorer/index.html in your browser.
Step2: Ensure that your firewall or antivirus software is not blocking connections to localhost.
Step3: Ensure that Microsoft.Azure.Cosmos
is up to date.
Step4: Sometimes restarting the emulator and your system can resolve connection issues.
For more details, refer the Develop locally using the Azure Cosmos DB emulator and checkout a video on Setting Up Azure Cosmos DB Emulator for Development.
I hope this information helps, please do let us know if you have any Queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful. And, if you have any further query do let us know.