簡體   English   中英

無法從Azure中部署的App API訪問Azure中的DocumentDB集合

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

我在訪問集合DocumentDB的API時遇到問題。 如果我在開發環境(Visual Studio)中運行API,它將運行良好並返回集合中的所有JSON文檔。 等待時間約為1分鍾。 但是,當將API部署在Azure中時,它不會返回任何內容。 我尚未在API中實現Application Insight。

該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,沒有分區。

這些症狀表明該應用程序無法連接到數據庫。 這可能是由於應用程序無法讀取Azure應用程序服務設置中定義的數據庫終結點和密鑰。

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

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

您可以在此處找到有關如何在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