你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

CosmosClient 构造函数

定义

重载

CosmosClient()

创建用于模拟测试的新 CosmosClient

CosmosClient(String, CosmosClientOptions)

使用连接字符串创建新的 CosmosClient

CosmosClient 是线程安全的。 建议在应用程序的生存期内维护 CosmosClient 的单个实例,从而实现高效的连接管理和性能。 请参阅 中的 https://docs.microsoft.com/azure/cosmos-db/performance-tips性能指南。

CosmosClient(String, String, CosmosClientOptions)

使用帐户终结点 URI 字符串和帐户密钥创建新的 CosmosClient

CosmosClient 是线程安全的。 建议在应用程序的生存期内维护 CosmosClient 的单个实例,从而实现高效的连接管理和性能。 请参阅 中的 https://docs.microsoft.com/azure/cosmos-db/performance-tips性能指南。

CosmosClient()

创建用于模拟测试的新 CosmosClient

protected CosmosClient ();
Protected Sub New ()

适用于

CosmosClient(String, CosmosClientOptions)

使用连接字符串创建新的 CosmosClient

CosmosClient 是线程安全的。 建议在应用程序的生存期内维护 CosmosClient 的单个实例,从而实现高效的连接管理和性能。 请参阅 中的 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)

参数

connectionString
String

cosmos 帐户的连接字符串。 例如: https://mycosmosaccount.documents.azure.com:443/;AccountKey=SuperSecretKey;

clientOptions
CosmosClientOptions

(可选) 客户端选项

示例

CosmosClient 使用连接字符串创建,并配置为使用“美国东部 2”区域。

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

注解

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

适用于

CosmosClient(String, String, CosmosClientOptions)

使用帐户终结点 URI 字符串和帐户密钥创建新的 CosmosClient

CosmosClient 是线程安全的。 建议在应用程序的生存期内维护 CosmosClient 的单个实例,从而实现高效的连接管理和性能。 请参阅 中的 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)

参数

accountEndpoint
String

要使用的 cosmos 服务终结点

authKeyOrResourceToken
String

用于创建客户端的 cosmos 帐户密钥或资源令牌。

clientOptions
CosmosClientOptions

(可选) 客户端选项

示例

CosmosClient 是使用 AccountEndpoint、AccountKey 或 ResourceToken 创建的,并配置为使用“美国东部 2”区域。

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

注解

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

适用于