I have a winform app in .NET 4.0 with database (SQLite). I need to add an option for user to be able to change the path to the file containing the database - in short, to change the connection string. I used app.config to save connection string like this:
<connectionStrings>
<add name="connectionString" connectionString="Data Source=D:\myDatabase.db; FailIfMissing=True; Version=3"/>
</connectionStrings>
Is there a way to allow user to modify app.config file (it is located in Program Files folder)? I do not want to run the app as an administrator, is there a way to give administrator rights to user temporarely, only when trying to modify app.config file?
If you have any better suggestion for persistently storing connection string, please share.
Thank you!
EDIT: I can actually change app.config file:
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["connectionString"].ConnectionString = "Data Source=" + path + "; FailIfMissing=True; Version=3";
config.Save();
ConfigurationManager.RefreshSection("connectionStrings");
Problem is when user is not an administrator, access to the file is denied. Is there a workaround (I do not want to run the app as administrator)? Or is there a better way to store my connection string?