简体   繁体   中英

Updating Database during installation

I have a C# application that is largely a front-end to a database that manages property rental. However, the database is evolving along with the software and sometimes needs to be updated.

I would like to be able to update the database from the installer instead of deploying a set of sql files and the msi. I've considered writing it into the launch of the program, but that might cause some funny things to occur if two people launch the program at the same time. The program is installed on a single server, and then ran remotely my several people, so doing the update in the installer wouldn't have this people.

How can I update the database during an installation of the program?

I recall an application I inherited that faced a similar situation, the programmer who wrote the app keyed off two fields in the database, one - the current version number prior to any installer running it would check the version number so if the database had a higher version than the installer was attempting, the install would abort, secondly, in the same table that stored the version/build, another column stored the state of the database ie operational/upgrade in process etc, so if the version # was older, that was the second check, if an install was already in progress the secondly launched installer would abort. Even in cases of very close simultaneous launches, one of the installers would acquire the lock first.

edit: by abort etc, I mean the db portion of the upgrade would not run.

Updating a production database with an end-user installation can be risky, as you've discovered. Here are a few options:

  1. If you can't be present for the installation, you may want to instruct your clients to contact you for installation so you can walk them through the process.

  2. In future revisions, include a special table in the database. When installation begins, write a record into that table that indicates an upgrade is in progress. Don't allow any clients to connect while the installation is running.

  3. Don't overwrite the existing production database. Instead, restore your new database to the server through a script, then use an SSIS process to move data from the previous version database to the new database. This is a good idea regardless, to protect against an installation failure that might corrupt their production database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM