web.config and app.config confusion

Create a new sectionGroup in configSections called applicationSettings and paste your app.config configuration into web.config as shown below and then you can override your app.config settings. <?xml version=”1.0″ encoding=”utf-8″ ?> <configuration> <configSections> <sectionGroup name=”applicationSettings” type=”System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ > <section name=”Playground.ConfigurationOverride.DataAccess.Properties.Settings” type=”System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” /> </sectionGroup> </configSections> <applicationSettings> <Playground.ConfigurationOverride.DataAccess.Properties.Settings> <setting name=”MySetting” … Read more

Changing App.config at Runtime

I understand this is quite an old thread, but I could not get the listed methods to work. Here is a simpler version of the UpdateAppSettings method (using .NET 4.0): private void UpdateAppSettings(string theKey, string theValue) { Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (ConfigurationManager.AppSettings.AllKeys.Contains(theKey)) { configuration.AppSettings.Settings[theKey].Value = theValue; } configuration.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(“appSettings”); } Pretty readable and avoids … Read more

App.config connection string relative path

You can specify a relative path as described in Lefty’s answer. However this will be relative to the current working directory, which will not necessarily be the directory containing your executable. One way round this is to modify the connection string before using it, e.g. In app.config: connectionString=”data source={AppDir}\data\EmailDatabase.sqlite In your code: ConnectionStringSettings c = … Read more

Visual Studio always selects the wrong xsd for App.config

I interpret the problem as follows: the file DotNetConfig.xsd has wrong (or not full) definition of the <startup> element. Line 230 of all DotNetConfig.xsd, DotNetConfig35.xsd, DotNetConfig30.xsd and DotNetConfig20.xsd files contains <xs:element name=”startup” vs:help=”configuration/startup” /> On the other side Microsoft describes the startup settings schema as a non-empty element. So I suggest to replace the above … Read more

How to enable configSource attribute for Custom Configuration Section in .NET?

The actual file, must be placed relative to the project output folder (by default “\bin\debug” or “bin\Release” Also, The file in your project tree, look at the properties of the file, and make sure the “Copy to Output Directory” setting is set to “Copy Always” or “Copy if Newer” EDIT: make sure the separate config … Read more