I made an application that is able to change its app.config (the connection string part). I tried several solutions and this proved to be the easiest way to solve one of my problems. This is the code I use:
ConnectionStringSettings postavke = new ConnectionStringSettings("Kontrolor.Properties.Settings.KontrolorConnectionString", constring);
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings.Clear();
config.ConnectionStrings.ConnectionStrings.Add(postavke);
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection(config.ConnectionStrings.SectionInformation.SectionName);
This code is placed inside a button_click method, and when I click that button and restart the application the changes are visible. My question is this - is there a way to do it from another (independent) application that would enable the user to create the connection string by entering the required values into a textBox or selecting it from comboBox (he needs only to enter the IP of the server and the name of the database). By doing that, the first application would be preprepared and there would be no need to restart it to apply changes. Is there a way to do this?