我已经使用.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,我想找到解决方案,该如何停止或尝试捕获它。
答案 0 :(得分:0)
您可以使用documentClient
对象上的方法OpenAsync()
来检查是否
它已成功初始化。
它将引发End Point not reachable
和Invalid Authorization Key
的异常
DocumentClient documentClient = new DocumentClient(new Uri(endPointUri), authKey);
try
{
documentClient.OpenAsync().GetAwaiter().GetResult();
}
catch(Exception ex)
{
// Handle Exception Here
}
您可以继续查询DocumentClient
的成功初始化