4

I created an AzureCosmosDb account in Azure in order to use MongoDb.

I got a connection string that works perfectly but it ends by /?ssl=true&replicaSet=globaldb. So I am unable to store it in the connectionStrings section of my web.config file. It says :

Entity 'replicaSet' not defined
Expecting ;
Application Configuration file "Web.config" is invalid. '=' is an unexpected token. The expected token is ';'.

I don't want to store it in a constant so is there a way to make it work ?

Thanks.

PMerlet
  • 2,568
  • 4
  • 23
  • 39
  • Why not strip that portion in web.config and just append it via your app? There are no credentials or changing variables in that portion. – David Makogon Jul 21 '17 at 15:55
  • This is not a direct answer but I was able to store your db connection string value as an Azure WebApp setting via the Azure Portal. I have also stored my own pre Cosmos DocumentDb connection string in my own local Web.Config the difference being there is no reference to replicaSet in my string. I wonder if you could simplify your CosmosDb declaration on Azure as a test to avoid the replicaSet portion. – camelCase Jul 21 '17 at 15:56
  • @DavidMakogon I am not sure appending some text to a connection string was the exact purpose of a connectionstring. I see it has a variable that I can change without editing my code. – PMerlet Jul 21 '17 at 16:06
  • @camelCase I tried to remove the replicaSet but I cannot connect to the DB. Thanks for the Azure setting tip. – PMerlet Jul 21 '17 at 16:07

1 Answers1

6

web.config file is an XML file, so any value has to be a valid XML.

Нou need to replace & sign with &:

/?ssl=true&replicaSet=globaldb

Here is a similar question.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107