languages | products | page_type | description | ||||
---|---|---|---|---|---|---|---|
|
|
sample |
This sample shows you how to use the Azure Cosmos DB service to store and access data from a .NET console application. |
This sample shows you how to use the Azure Cosmos DB service to store and access data from a .NET console application.
For a complete end-to-end walkthrough of creating this application, please refer to the full tutorial on the Azure Cosmos DB documentation page.
-
Before you can run this sample, you must have the following prerequisites:
- An active Azure Cosmos DB account - If you don't have an account, refer to the Create a database account article.
- NET Core SDK 3+.
-
Clone this repository, or download the zip file.
-
Browse to the
src
folder. -
Run
dotnet build
to restore all packages. -
Retrieve the URI and PRIMARY KEY (or SECONDARY KEY) values from the Keys blade of your Azure Cosmos DB account in the Azure portal. For more information on obtaining endpoint & keys for your Azure Cosmos DB account refer to View, copy, and regenerate access keys and passwords. If you are using the Emulator, you can also use its credentials.
-
In the Program.cs file, located in the
src
directory, find EndPointUri and AuthorizationKey and replace the placeholder values with the values obtained for your account.
private const string EndpointUrl = "https://<your-account>.documents.azure.com:443/";
private const string AuthorizationKey = "<your-account-key>";
- You can now run the application with
dotnet run
.
The code included in this sample is intended to get you quickly started with a .NET console application that connects to Azure Cosmos DB.
- Azure Cosmos DB Documentation
- Azure Cosmos DB .NET SDK for SQL API
- Azure Cosmos DB .NET SDK Reference Documentation
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.