问题
we have a client application with a local database. Once in a while we need to provide updates to the database ranging from changing a column , adding a column etc etc. We want to check if the application is run for the first time deploy the database. If not, check for updates. What would be the easiest way to deploy database updates through click once. Could this be deploying the scripts to a folder and having the local app check and run?
回答1:
use entity framework with automatic migrations turned on, and make sure all changes to the database are handled via EF migration.
when you decide to change server app - you do the following:
- Change main app
- Change client app schema
- Push new build setting version to be current - this way when user starts client app, it will not work unless latest version is downloaded and run
- When version is downloaded, run EF migration scripts on start.
回答2:
I recommend that you include the scripts for updating the database. Include a version number in the script(s). Also store a version number in the database. Have the app check to see if there are scripts included. You can use some kind of template name to check for them with a wildcard, or put them in a resource string. If there are scripts, compare the version number with the one in the database to see if you need to execute the scripts, and if so, do so and then update the version in the database.
Another tip -- please don't store your data in the DataDirectory and rely on ClickOnce to carry it forward. It's dangerous. Check out this article telling you how to handle data so it doesn't get mucked up by ClickOnce updates.
来源:https://stackoverflow.com/questions/32827749/deploying-databases