Search code examples
wpfdatabasebuild-process

Build Action of Database


I have a WPF application. My question is What should be the build action for the database in my case. I have a database but every time I build my solution the database entries are removed and a new database is created. What build action should I keep for my database to overcome this problem.


Solution

  • How come you remove all of your Database data? What happens to your data then? Is it possible in a live system?

    To overcome this problem, you should keep track of your DB changes as DB scripts. This means that by any DB change, you should keep its relevant script somewhere in your source control. The scripts should be traceable. This means that if you want to migrate from release A to release D, you should know which scripts should be executed for the DB migration.

    Here is the solution we use in our project.

    1. Each developer keeps a script in source control for any DB change.
    2. The scripts are numbered as SVN revision numbers, e.g. 2835.sql.
    3. While building the application, all scripts are copied to the application installer. But, by comparing the current installed version and the new version, the installer knows which scripts should be executed.
    4. Using this way, the migration becomes and easy process.