Reputation: 761
I change my connection String in app.config at runtime. It worked perfectly for users with Administrator rights But it is Not worked for users without Administrator Rights.
There is any way to handle this problem. My code for changing the app.config file is.
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["main"].ConnectionString = "Data Source=serverName;Initial Catalog=UrgentSIMDelivery;Integrated Security=true";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("connectionStrings");
Upvotes: 0
Views: 1237
Reputation: 4958
exePath = Path.Combine( exePath, "MyApp.exe" );
Configuration config = ConfigurationManager.OpenExeConfiguration( exePath );
var setting = config.AppSettings.Settings[SettingKey];
if (setting != null)
{
setting.Value = newValue;
}
else
{
config.AppSettings.Settings.Add( SettingKey, newValue);
}
config.Save();
Source https://stackoverflow.com/a/3678953/3156647
Upvotes: 1