I want to change the app.setting connection string at the run time. I have some code to change it but i can't do this. there is no error appear during the run time. But there is no change during execution.
This is my partial code :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Punch_Uploader.Properties.Settings.testConnectionString"
connectionString="server=localhost;User Id=root;password=test123;database=test"
providerName="MySql.Data.MySqlClient" />
<add name="Punch_Uploader.Properties.Settings.testConnectionString1"
connectionString="server=172.23.2.52;User Id=root;password=test123;database=test"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
</configuration>
And:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings.Add(
new ConnectionStringSettings("Punch_Uploader.Properties.Settings.testConnectionString2",
String.Format(
"server={0};Port={1}; database={2};User Id={3};password={4};providerName={5}",
"172.23.2.32", "3306", "test", "root", "test123", "MySql.Data.MySqlClient")
)
);
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("connectionStrings");
MessageBox.Show(ConfigurationManager
.ConnectionStrings["Punch_Uploader.Properties.Settings.testConnectionString2"]
.ConnectionString);
The above code is not working for me....
Please help me to fix this.