代码之家  ›  专栏  ›  技术社区  ›  Duc Nguyen

“停止”无法访问终结点。“刷新缓存并重试”当无法使用.NET SDK连接到Azure Cosmos DB SQL API时

  •  0
  • Duc Nguyen  · 技术社区  · 7 年前

    我正在使用.NET SDK Microsoft.Azure.DocumentDB 在Azure上与cosmos db合作。 我的网络无法连接到cosmos db(代理、网络…)时遇到问题

    例子:

       this.client = new DocumentClient(new Uri(EndpointUrl), PrimaryKey, new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp,
                RetryOptions = new RetryOptions {MaxRetryAttemptsOnThrottledRequests = 5, 
                MaxRetryWaitTimeInSeconds= 5 },
                RequestTimeout = new TimeSpan(1000)});
    var a = await this.client.CreateDatabaseIfNotExistsAsync(new Database { Id = "FamilyDB" });
    

    我的应用程序循环永远保持一致 CreateDatabaseIfNotExistsAsync 以及消息:

    Endpoint not reachable. Refresh cache and retry
    Failover happening. retryCount 6
    RefreshLocationAsync() refreshing locations
    An error occurred while sending the request. ---> System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
    Endpoint not reachable. Refresh cache and retry
    Failover happening. retryCount 7
    RefreshLocationAsync() refreshing locations
    An error occurred while sending the request. ---> System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
    ....
    

    我不能停下来或试着抓住它,我试着 requestoption requestTimeout 但它不起作用。

    0 回复  |  直到 6 年前
        1
  •  0
  •   jophab    6 年前

    你可以用这个方法 OpenAsync() documentClient 已成功初始化。

    它将为 End Point not reachable 以及 Invalid Authorization Key

    DocumentClient documentClient = new DocumentClient(new Uri(endPointUri), authKey);
    
    try
        {
            await documentClient.OpenAsync();
        }
    
    catch(Exception ex)
        {
            // Handle Exception Here
        }
    

    您可以继续查询成功初始化的 DocumentClient

    推荐文章