CosmosClient Constructors

Definition

Overloads

CosmosClient()

Create a new CosmosClient used for mock testing

CosmosClient(String, CosmosClientOptions)

Creates 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 the performance guide.

CosmosClient(String, TokenCredential, CosmosClientOptions)

Creates a new CosmosClient with the account endpoint URI string and TokenCredential.

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 the performance guide.

CosmosClient(String, String, CosmosClientOptions)

Creates 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 the performance guide.

CosmosClient()

Create a new CosmosClient used for mock testing

protected CosmosClient ();
Protected Sub New ()

Applies to

CosmosClient(String, CosmosClientOptions)

Creates 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 the performance guide.

public CosmosClient (string connectionString, Microsoft.Azure.Cosmos.CosmosClientOptions clientOptions = default);
new Microsoft.Azure.Cosmos.CosmosClient : string * Microsoft.Azure.Cosmos.CosmosClientOptions -> Microsoft.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

See also

Applies to

CosmosClient(String, TokenCredential, CosmosClientOptions)

Creates a new CosmosClient with the account endpoint URI string and TokenCredential.

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 the performance guide.

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

Parameters

accountEndpoint
String

The cosmos service endpoint to use.

tokenCredential
TokenCredential

TokenCredentialThe token to provide AAD token for authorization.

clientOptions
CosmosClientOptions

(Optional) client options

Applies to

CosmosClient(String, String, CosmosClientOptions)

Creates 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 the performance guide.

public CosmosClient (string accountEndpoint, string authKeyOrResourceToken, Microsoft.Azure.Cosmos.CosmosClientOptions clientOptions = default);
new Microsoft.Azure.Cosmos.CosmosClient : string * string * Microsoft.Azure.Cosmos.CosmosClientOptions -> Microsoft.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

See also

Applies to