简体   繁体   中英

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. If I run the API from my development environment (Visual Studio) it works well and returns all JSON documents in the collections. The latency time is about 1 minute. But when the API is deployed in Azure, it don not return anything. I have not yet implemented Application Insight in the API.

The C# code for the API is:

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.

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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