Share via


CosmosClient Constructors

Definition

Overloads

CosmosClient()

Create a new CosmosClient used for mock testing

CosmosClient(String, CosmosClientOptions)

Create a new CosmosClient with the connection string

CosmosClient is thread-safe. Its recommended to maintain a single instance of CosmosClient per lifetime of the application which enables efficient connection management and performance. Please refer to performance guide at https://docs.microsoft.com/azure/cosmos-db/performance-tips.

CosmosClient(String, String, CosmosClientOptions)

Create a new CosmosClient with the account endpoint URI string and account key

CosmosClient is thread-safe. Its recommended to maintain a single instance of CosmosClient per lifetime of the application which enables efficient connection management and performance. Please refer to performance guide at https://docs.microsoft.com/azure/cosmos-db/performance-tips.

CosmosClient()

Create a new CosmosClient used for mock testing

protected CosmosClient ();
Protected Sub New ()

Applies to

CosmosClient(String, CosmosClientOptions)

Create a new CosmosClient with the connection string

CosmosClient is thread-safe. Its recommended to maintain a single instance of CosmosClient per lifetime of the application which enables efficient connection management and performance. Please refer to performance guide at https://docs.microsoft.com/azure/cosmos-db/performance-tips.

public CosmosClient (string connectionString, Azure.Cosmos.CosmosClientOptions clientOptions = default);
new Azure.Cosmos.CosmosClient : string * Azure.Cosmos.CosmosClientOptions -> Azure.Cosmos.CosmosClient
Public Sub New (connectionString As String, Optional clientOptions As CosmosClientOptions = Nothing)

Parameters

connectionString
String

The connection string to the cosmos account. ex: https://mycosmosaccount.documents.azure.com:443/;AccountKey=SuperSecretKey;

clientOptions
CosmosClientOptions

(Optional) client options

Examples

The CosmosClient is created with the connection string and configured to use "East US 2" region.

using Microsoft.Azure.Cosmos;

CosmosClient cosmosClient = new CosmosClient(
            "account-endpoint-from-portal", 
            "account-key-from-portal", 
            new CosmosClientOptions()
            {
                ApplicationRegion = Regions.EastUS2,
            });

// Dispose cosmosClient at application exit

Remarks

https://docs.microsoft.com/azure/cosmos-db/performance-tips https://docs.microsoft.com/azure/cosmos-db/troubleshoot-dot-net-sdk

Applies to

CosmosClient(String, String, CosmosClientOptions)

Create a new CosmosClient with the account endpoint URI string and account key

CosmosClient is thread-safe. Its recommended to maintain a single instance of CosmosClient per lifetime of the application which enables efficient connection management and performance. Please refer to performance guide at https://docs.microsoft.com/azure/cosmos-db/performance-tips.

public CosmosClient (string accountEndpoint, string authKeyOrResourceToken, Azure.Cosmos.CosmosClientOptions clientOptions = default);
new Azure.Cosmos.CosmosClient : string * string * Azure.Cosmos.CosmosClientOptions -> Azure.Cosmos.CosmosClient
Public Sub New (accountEndpoint As String, authKeyOrResourceToken As String, Optional clientOptions As CosmosClientOptions = Nothing)

Parameters

accountEndpoint
String

The cosmos service endpoint to use

authKeyOrResourceToken
String

The cosmos account key or resource token to use to create the client.

clientOptions
CosmosClientOptions

(Optional) client options

Examples

The CosmosClient is created with the AccountEndpoint, AccountKey or ResourceToken and configured to use "East US 2" region.

using Microsoft.Azure.Cosmos;

CosmosClient cosmosClient = new CosmosClient(
            "account-endpoint-from-portal", 
            "account-key-from-portal", 
            new CosmosClientOptions()
            {
                ApplicationRegion = Regions.EastUS2,
            });

// Dispose cosmosClient at application exit

Remarks

https://docs.microsoft.com/azure/cosmos-db/performance-tips https://docs.microsoft.com/azure/cosmos-db/troubleshoot-dot-net-sdk

Applies to