我尝试从我的 asp.net 网站连接 documentdb,但收到此错误。
系统中不存在指定id的实体
DocumentClientException:系统中不存在具有指定 ID 的实体
代码如下,在aspx代码后面
protected async void Page_Load(object sender, EventArgs e)
{
Response.Write("Page Load<br/>");
await GetData();
}
public async Task GetData()
{
try
{
Response.Write("<br/> Get Data function Start<br/><br/>");
using (var client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["endpoint"]), ConfigurationManager.AppSettings["authKey"]))
{
//await client.OpenAsync();
RequestOptions reqOpt = new RequestOptions { PartitionKey = new PartitionKey(209) };
var parameters = new dynamic[] { 1 };
StoredProcedureResponse<object> result = await client.ExecuteStoredProcedureAsync<object>(
UriFactory.CreateStoredProcedureUri(ConfigurationManager.AppSettings["database"], ConfigurationManager.AppSettings["pcsd"], "GetMemberbyId"), reqOpt, parameters);
Response.Write(result.Response.ToString());
}
Response.Write("<br/><br/> Get Data function End");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
存储过程如下
function GetMemberbyId(memId) {
var collection = getContext().getCollection();
//return getContext().getResponse().setBody('no docs found');
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT * FROM root m where m.memberId='+memId,
function (err, feed, options) {
if (err) throw err;
// Check the feed and if empty, set the body to 'no docs found',
// else take 1st element from feed
if (!feed || !feed.length) getContext().getResponse().setBody('no docs found');
else getContext().getResponse().setBody(feed);
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
在我的本地主机中,它工作正常,但网站发布到 azure 网络应用程序并运行时,我遇到了上述错误
最佳答案
我刚刚花了几个小时对此进行故障排除,却发现我已将实例防火墙设置到无法本地连接的程度。请记住,即使您无法通过 API/C# 客户端直接访问,Azure 门户文档查询显然仍然可以工作。
尝试设置防火墙以允许所有网络暂时检查访问。
关于azure - DocumentDB/CosmosDB - 系统中不存在具有指定 ID 的实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43723470/