0

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.

  • Edgar, which version of C# SDK are you using? Are you sure you are connecting to the same database/collection in your app in azure(best way to confirm is to print them out as log)? Can you also check if the first CreateDocumentQuery is returning 0 results or it's the second one. DateTime.Parse will throw if some of your documents doesn't have dateCreated property, so ensure that's not the case. I'd add enough logging at various places to see where the issue is. Your code looks good to me. – Rajesh Nagpal Sep 30 '16 at 00:41
  • since you say the same code runs locally... have you confirmed that your connection string is correct (e.g. you're properly setting/retrieving database and collection name via `AppSettings`)? – David Makogon Sep 30 '16 at 02:21

1 Answers1

0

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/

Andrew Liu
  • 8,045
  • 38
  • 47