John
John

Reputation: 762

DocumentDB connection string

Azure application settings (for azure function) has a option for a DocumentDB connection string

Anyone have any idea how this should be populated/formatted?

i currently use:

var documentDbEndpointUri = new Uri(ConfigurationManager.AppSettings["DocumentDbEndpointUri"]);
            var documentDbAuthKey = ConfigurationManager.AppSettings["DocumentDbAuthKey"];
            return new DocumentClient(documentDbEndpointUri, documentDbAuthKey);

Although I'd like to switch to a single value connection string.

Upvotes: 10

Views: 25955

Answers (2)

Fei Han
Fei Han

Reputation: 27793

Firstly, as @Gaurav Mantri said in comment, currently DocumentClient does not have constructor overloads using connection string, you cannot directly use a connection string to create an instance of DocumentClient even if you provide/add connection string for DocumentDB in Azure application settings.

enter image description here

Note: here is a feedback for this issue, if you have same feature request, you can vote for it.

Secondly, If you’d like to access the DocumentDB service via DocumentClient, you can add both DocumentDbEndpointUri and DocumentDbAuthKey in App settings, and then read them in function code.

var serviceEndpoint = System.Configuration.ConfigurationManager.AppSettings["DocumentDbEndpointUri"];
var authKey = System.Configuration.ConfigurationManager.AppSettings["DocumentDbAuthKey"];

//or
//var serviceEndpoint = Environment.GetEnvironmentVariable("DocumentDbEndpointUri");
//var authKey = Environment.GetEnvironmentVariable("DocumentDbAuthKey");

Upvotes: 2

hsedidin
hsedidin

Reputation: 452

Try AccountEndpoint=https://accountname.documents.azure.com:443/‌​;AccountKey=accountk‌​ey==;Database=database

Upvotes: 26

Related Questions