Change App.Config file at Runtime Not Worked for users without Administrator rights

StackOverflow https://stackoverflow.com/questions/21231319

  •  30-09-2022
  •  | 
  •  

Question

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");
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top