History

History of .net

Thursday, 24 January 2013


Method to Replace a connection string in Appconfig of a Application


private bool Replaceconnectionstr(string filepath, string KeyCode, string NewConnectionString)
{
try
{
string otherExePath = @filepath;
Configuration otherConfig = ConfigurationManager.OpenExeConfiguration(otherExePath);
string otherSetting = otherConfig.AppSettings.Settings[KeyCode].Value;
otherConfig.AppSettings.Settings[KeyCode].Value = NewConnectionString;
otherConfig.Save();
return true;
}
catch (Exception ex)
{
ex.ToString();
return false;
}
}

No comments:

Post a Comment