ConfigurationManager.OpenExeConfiguration - is it possible to open and edit app.config?

StackOverflow https://stackoverflow.com/questions/22227826

  •  10-06-2023
  •  | 
  •  

Domanda

I tried to find some information in topic: EntityConnection error The specified named connection is either not found in the configuration

Now I found another solution - to open .config file and create key in connectionstrings. But my question is that - Entity Model add connectionstrings to app.config file. ConfigurationManager.OpenExeConfiguration open myApplication.exe.config file.

  • is it possible to change that application will use myApplication.exe.config ?
  • or maybe there is way to open app.config file and add connectionString?
È stato utile?

Soluzione

Use OpenMappedExeConfiguration in combination with ExeConfigurationFileMap to specify the file name:

ConfigurationManager.OpenMappedExeConfiguration(
   new ExeConfigurationFileMap() { ExeConfigFilename = "your file path here" }, ConfigurationUserLevel.None);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top