I have an app using a SQLite db, and I need the ability for the user to move the data file and point the app to where it moved to. I used the Entity Framework to create the model, and by default it puts the connection string in the App.Config file. From what I've read if I make changes to the connection string there then they won't take effect until the app is restarted. That seems a bit clunky for my use. I see how I can init my model and pass in a custom string but I'm unsure what the best practice is in where to store basic user prefrences such as this? Ini, Registry, somewhere else? I don't want the user to have to "Open" the file each time, just when it relocates and then the app will try to auto open from then on.
views:
147answers:
3Have a look at Application Settings for an overview of how to create user-specific config settings which can be saved to a user.config file. The registry is more or less abandoned in favour of the new xml-based config file system.
You don't have to use the Connection String that is added to the App.Config. You can skip adding it actually, in the EDMX wizard.
You then need simply have the connection string live anywhere you choose and pass it into your ObjectContext constructor.
You can put the connection string in an external file, the registry, or wherever you choose.
It might make sense to have a static class that generates the connection string, and grabs the file location from a common source that the user can change (i.e. registry, file on disk, environment variable, etc.)
You could create a settings class and then serialise it to an xml file with a predfined name in a location that is set via the app.config file. You could then control how frequently the file was read into memory yourself. The only timeyou would need to restart the app was if the location of the settings file changed.