DocumentDB/CosmosDB-具有指定ID的实体在系统中不存在 [英] DocumentDB / CosmosDB - Entity with the specified id does not exist in the system
问题描述
我试图从asp.net网站连接documentdb,但出现此错误.
i tried to connect documentdb from my asp.net website but i am getting this error.
系统中不存在具有指定ID的实体
DocumentClientException:具有指定ID的实体在系统中不存在
DocumentClientException: Entity with the specified id does not exist in the system
在aspx代码后面的代码如下
code as follows in aspx code behind
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.');
}
在我的本地主机上运行正常,但网站已发布到天蓝色的Web应用程序并正在运行,但我遇到了以上错误
in my localhost it's working fine but website published to azure web apps and running i am getting above error
推荐答案
我只花了几个小时对它进行故障排除,却发现我已经对实例进行了防火墙保护,无法在本地进行连接.请记住,即使您没有通过API/C#客户端的直接访问,Azure门户文档查询显然仍然可以工作.
I just spent a couple of hours troubleshooting this, only to find that I had firewalled my instance to a point where I could not connect locally. Keep in mind that the Azure portal document query will obviously still work even when you have no direct access via the API / C# client.
尝试将防火墙设置为允许所有网络临时检查访问权限.
Try setting the firewall to allow All Networks temporarily to check access.
这篇关于DocumentDB/CosmosDB-具有指定ID的实体在系统中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!