Hi, I try to change connection string, but it is only change in memory, but not in App.Config file, below is the code I am using
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings[1].ConnectionString = "metadata=res://*/TCSModel.csdl|res://*/TCSModel.ssdl|res://*/TCSModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=" + cmbServerName.Text + ";Initial Catalog=" + cmbDatabase.Text + ";User ID=" + txtUserName.Text.Trim() + ";Password=" + txtPassword.Password + ";Persist Security Info=True;MultipleActiveResultSets=True'";
config.ConnectionStrings.ConnectionStrings[1].Name = "TCSEntities";
config.ConnectionStrings.ConnectionStrings[1].ProviderName = "System.Data.EntityClient";
config.Save(ConfigurationSaveMode.Full, true);
ConfigurationManager.RefreshSection("connectionStrings");
What is missing or wrong in the above code?
Thanks