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

时间:2018-11-29 07:05:28

标签: azure-cosmosdb azure-cosmosdb-sqlapi

我已经使用.NET SDK Microsoft.Azure.DocumentDB在Azure上使用cosmos db。 我的网络无法连接到cosmos db时出现问题(代理,网络等) 示例:

 import HeatChart from '../heatChartContainer';

 export default {
axisColors: axisColors, 
options: {
    credits: {
        enabled: false
    },
    chart: {
        height: 428
    },
    colorAxis: {
        minColor: axisColors.minColor,
        maxColor: axisColors.maxColor,
        labels: {
            style: style
        }
    },
    tooltip: {
        useHTML: true,
        padding: 2,
        headerFormat: '<div class="padding-0-10 padding-b-10"><table>',
        pointFormat: '<tr><td colspan="2"><h5><strong>{point.name}</strong></h5></td></tr>' +
            '<tr><td style="padding-right: 5px;">{point.type} Count: </td><td>{point.colorValue}</td></tr>' +
            '<tr><td style="padding-right: 5px;">Device Count: </td><td>{point.value}</td></tr>',
        footerFormat: '</table></div>'
    },
    plotOptions: {
        series: {
            cursor: 'pointer',
                enabled: true,
                allowOverlap: true,
                style: {
                    fontFamily: "'univers', Arial, sans-serif",
                    fontSize: 12,
                    color: "#FFF",
                    stoke: "#FFF"
                }
            },
            point: {
                events: {
                    click: function() {
  HeatChart.loadHierarchy({chartType:'momentaryDisturbance', name:this.name, previousLevel: this.previousLevel}) //this is the one I need to call

                    }
                }
            }
        }
    }

我的应用程序永远在CreateDatabaseIfNotExistsAsync行中循环,无法尝试捕获消息:

   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" });

无法停止或尝试捕获它,我尝试使用requestoption,requestTimeout,但无法正常工作。 因此,如果我无法连接到cosmos db,我想找到解决方案,该如何停止或尝试捕获它。

1 个答案:

答案 0 :(得分:0)

您可以使用documentClient对象上的方法OpenAsync()来检查是否 它已成功初始化。

它将引发End Point not reachableInvalid Authorization Key的异常

DocumentClient documentClient = new DocumentClient(new Uri(endPointUri), authKey);

try
    {
        documentClient.OpenAsync().GetAwaiter().GetResult();
    }

catch(Exception ex)
    {
        // Handle Exception Here
    }

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