5

I have a c# .net application that has been distibuted separately to several clients, Once in a while we add some new features or fix some bugs and frequently make changes in the DB. I use click once deployment approach to update exe to my client pcs. SQL server instance has been installed on their system.

I want to know how could i update their sql database with each exe updation.

Kindly keep in mind this is possible that a client is working on version 2 and never updated to version 3 but when version 4 is released, then he updates the application. In such case i need to execute two scripts on his database. One for version 3 and other for current version which is 4.

Thanks

Manvinder
  • 4,495
  • 16
  • 53
  • 100

4 Answers4

2

Assuming you have a stored procedure/script that can update one version to another, and assuming you can't load any other exe that will run it, why don't you just include a call to run it at the start of the new version? Have there be a a check when the software loads that looks to see if they're using the correct version of the database, if not, update it. To handle issues like going from version 2 up to 4, just make sure the database itself keeps track of what version it currently is.

cost
  • 4,420
  • 8
  • 48
  • 80
  • So i need to keep all the scripts of the database in my executable so whenever user update the exe their respective script should be available. – Manvinder May 03 '12 at 10:46
0

You could try sqlcmd and just call the exe from within you application with the DB updates.

Rob
  • 1,071
  • 8
  • 10
0

This is a scenario which is best solved by using "Database Migrations". There are several tools available in the .net ecosystem to aid you with that. Some of the tools come with a separate runner, while others can be compiled as a .net assembly which you can include in your project.

Examples are:

Filip De Vos
  • 11,568
  • 1
  • 48
  • 60
0

I've created two components to tackle this issue:

1.

A WinForms app that analyses a certain SQL DB as well as a SQL Solution Folder containing scruipt files. It then mathces the script files to the SQL objects and lets me build a "Manifest.xml" containing an execution order for the various script files.

The script files for the tables contain per-version instructions on upgrading the table structure.

The builder then copies the relevant script files along with the manifest into a certain location. Usually I copy those along with my app if I'm not worried about overcrowding my app-folder. Otherwise I compress them to a password protected 7-zip.

2.

A command line app that unpacks (if needed) and executes the manifest. The actual work is done in a separate class library that can be integrated in my apps.

Then in my app whenever my appversion > dbversion I run the upgrade.

In setups where there's only a staging and production setup at one single customer and usually no app involved I'll use the stand-alone CLI app manually. It's an easy way to push updates, especially if you modified 20 views and REALLY don't feel like copy/pasting them all into SQL Mgt Studio :p

Vincent Vancalbergh
  • 3,267
  • 2
  • 22
  • 25