0
我有访问集合DocumentDB的API的问题。如果我从我的开发环境(Visual Studio)运行API,它运行良好,并返回集合中的所有JSON文档。等待时间约为1分钟。但是,当API部署在Azure中时,它不会返回任何内容。我还没有在API中实现Application Insight。从Azure中部署的App API无法访问Azure中的DocumentDB集合
的API的C#代码:
string DatabaseId = ConfigurationManager.AppSettings["database"];
string CollectionId = ConfigurationManager.AppSettings["collectionExperimentos"];
DocumentClient client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["endpoint"]), ConfigurationManager.AppSettings["authKey"],
new ConnectionPolicy
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
});
var collectionLink = UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId);
List<Experiment> experimentosList = new List<Experiment>();
experimentosList = client.CreateDocumentQuery<Experiment>(collectionLink).ToList();
experimentosList = experimentosList.OrderByDescending(experimentos => DateTime.Parse(experimentos.dateCreated)).ToList();
集合大小是160MB,也没有分区。
埃德加,其中C#SDK的版本是你使用?你确定你连接到你的应用程序在相同的数据库/集合天蓝色(最好的方式来确认是打印出来的日志)?你还可以检查第一个CreateDocumentQuery是返回0结果还是第二个。如果某些文档没有dateCreated属性,DateTime.Parse会抛出,所以确保不是这样。我会在各个地方添加足够的日志以查看问题所在。你的代码对我来说很好。 –
既然你说相同的代码在本地运行......你确认你的连接字符串是否正确(例如,你通过'AppSettings'正确设置/检索数据库和集合名称)? –