简体   繁体   English

无法从Azure中部署的App API访问Azure中的DocumentDB集合

[英]No Access to a collection of DocumentDB in Azure from an App API deployed in Azure

I have a problem with an API to access a collection DocumentDB. 我在访问集合DocumentDB的API时遇到问题。 If I run the API from my development environment (Visual Studio) it works well and returns all JSON documents in the collections. 如果我在开发环境(Visual Studio)中运行API,它将运行良好并返回集合中的所有JSON文档。 The latency time is about 1 minute. 等待时间约为1分钟。 But when the API is deployed in Azure, it don not return anything. 但是,当将API部署在Azure中时,它不会返回任何内容。 I have not yet implemented Application Insight in the API. 我尚未在API中实现Application Insight。

The C# code for the API is: 该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();

The collection size is 160MB and has no partitions. 集合大小为160MB,没有分区。

The symptoms suggest that the application is failing to connect to the database. 这些症状表明该应用程序无法连接到数据库。 This is likely due to the application failing to read the database endpoint and keys defined in the Azure App Service settings. 这可能是由于应用程序无法读取Azure应用程序服务设置中定义的数据库终结点和密钥。

string DatabaseId = ConfigurationManager.AppSettings["database"];
string CollectionId = ConfigurationManager.AppSettings["collectionExperimentos"];

DocumentClient client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["endpoint"]), ConfigurationManager.AppSettings["authKey"],

You can find more information on how to configure environment variables and connection strings in Azure App Service (I'm assuming it's a Web App) here: https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/ 您可以在此处找到有关如何在Azure App Service中配置环境变量和连接字符串的更多信息(我假设它是Web应用程序): https : //azure.microsoft.com/zh-cn/documentation/articles/web-站点配置/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM