3
Answers

How to update app.config file

Nilesh Dhande

Nilesh Dhande

10y
1.1k
1
Hello
 i am working on windows application in C#.now i want change connection string in app.confing through programitically using following code

 var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
            connectionStringsSection.ConnectionStrings["AdminDBConn"].ConnectionString = "Data Source=" + serverName + ";Initial Catalog=" + DbName + ";UID=" + userName + ";password=" + Password + "";
            config.Save();
            ConfigurationManager.RefreshSection("connectionStrings");

connection string save but when application is close then and again open then he picked up old connection string mean app.config does not update permantelly.

Answers (3)