Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > ClickOnce Deployment Questions
 

ClickOnce Deployment Questions

Hi,

I have a couple of problems relating to clickonce deployment that I was hoping someone could spread some light on.

Problem1:

I upload version 1.0.0.1 to my server and userA downloads via clickonce link, this version includes the DB (MS Access) in the data directory. I then discover a bug (not likely I know :-)) and fix this in version 1.0.0.1. I publish this new version but this time have to exclude the DB as I do not want to overwrite user A's data. User A opens the application is presented with the new version, they download and everything is ok, the database file is copied from the previous deployment to the new deployment. However user B comes along and downloads the application version 1.0.0.1, but this does not include the DB!

Question - How can I get it so that any user downloading also gets all the files from the previous versions?

Problem 2:

I now want to add an additional field to my DB to support some new functionality. I add the column, complete the CRUD code and upload version 1.0.0.2, The problem is that I need to upload the DB changes but doing this overwrites any previous versions (I know that older version of content files are copied and stored in .pre).

Question: How do I make DB changes and push these to my clients wihtout overwriting their data? If I have to do this programatically could anyone provide me with some samples?

I assumed that downloading he latest version would also install all the previous version, this does not seem to be the case and also the DB changes not integrated but merely copied over the top (well the newer version uses a different DB) rather that incorporate the changes made. I am now questioning whether ClickOnce deployment is right for me but it seems such a shame as I like the idea of all clients having the latest versions whether this be because they are updating older version or downloading the newest from the server.

Please help...

Ian Hannaford

ianhannaford  Thursday, June 15, 2006 11:25 PM

There's a whole system to handle the scenarios you described, but I'm not super experienced with them, so I'll try to give you my best understanding and some pointers...

When you mark a file in the Application Files dialog as a Data file, it is handled differently. When a user upgrades their application, I don't think the data files are downloaded again, only on first install they are downloaded.

So, when you download a new app that needs database updates, you need a way to update/migrate your database. So, I think there's a way...

On app startup, you use the System.Deployment.ApplicationDeployment.IsFirstRun property to determine if this is the first time this version of the app has been run (it's reset to false after each upgrade).

http://msdn2.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.isfirstrun.aspx

If true, you can call your "DatabaseUpgrade" method.You have to write all the code to modify/upgrade your database yourself.

The System.ApplicationDeployment.DataDirectory property can help you find your data file.

Theres some discussion of doing this in: http://msdn2.microsoft.com/en-us/library/d8saf4wy.aspx

I hope this helps.

David Guyer MSFT  Friday, June 16, 2006 5:07 AM

There's a whole system to handle the scenarios you described, but I'm not super experienced with them, so I'll try to give you my best understanding and some pointers...

When you mark a file in the Application Files dialog as a Data file, it is handled differently. When a user upgrades their application, I don't think the data files are downloaded again, only on first install they are downloaded.

So, when you download a new app that needs database updates, you need a way to update/migrate your database. So, I think there's a way...

On app startup, you use the System.Deployment.ApplicationDeployment.IsFirstRun property to determine if this is the first time this version of the app has been run (it's reset to false after each upgrade).

http://msdn2.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.isfirstrun.aspx

If true, you can call your "DatabaseUpgrade" method.You have to write all the code to modify/upgrade your database yourself.

The System.ApplicationDeployment.DataDirectory property can help you find your data file.

Theres some discussion of doing this in: http://msdn2.microsoft.com/en-us/library/d8saf4wy.aspx

I hope this helps.

David Guyer MSFT  Friday, June 16, 2006 5:07 AM

Hi David,

Thanks for the reply. I have found that you have to include the DB in all version but by setting the DB file as content and changing the 'Copy to Output Directory' to 'Copy if newer' means that new users downloading a later version of the aplication get the DB, however this only works if the DB is unchanged.

If any changes are made to the DB then the new user will get the new DB and the older users will also get the new DB, this causes the loss of data. The older DB with the data does exist in the Data directory under a directory called .pre

I think that the only way around this is to make the DB changes programmtically and never to change the DB through MS Access. If the user is downloading the latest version for the first time then they will automatically get the latest DB. For all other users the application code will have to check that this is not the first deployment and run sql update scripts to update their version of the DB.

This does not seem to be the most robust of solutions as Im not sure how to handle programatic updates or what to do if the update scripts fail for any reason, does thismean that the user DB will be left in a corrupt state?

I suppose I could back up the DB before performing the updates, if any fail then copy the old db back and roll back the application version. Does anyone have any sample code that will accomplish the above?

Thanks in advance

Ian Hannaford

ianhannaford  Friday, June 16, 2006 8:39 AM

Hi,

The general update logic is that you included the new DB with the new version of the app. By new DB I mean either the schema has changed, the content of the DB on the server has changed or both have changed. The migration logic can be as follows

if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed){// ClickOnce app
if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun){
if (File.Exists(System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory + ".pre/" + myDataFile.mdb) && File.Exists(System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory +myDataFile.mdb)
)
{ // File exists in both pre and Data Dir
// Need to migrate data from thedata file in the .pre folder

//ClickOnce dose not support any migration as it cannot make assumptions abt the data file schema.

}
else
//File does not exists ...so this is a first installanddon't do anything

}

}

If you are concerned about update failing on first run you can employ some mechnism that tell the app that the migration was successful. For eg. you can delete the data file from the .pre dir.

As you mentioned you can also back up the DB to make it more robust.

Thanks,
Sameer

Sameer Murudkar - MSFT  Thursday, June 22, 2006 6:58 AM

You can use google to search for other answers

Custom Search

More Threads

• Obfuscated program's settings are set to their default values after the program being updated.
• Forum login confusion
• Include .NET Cleanly with ClickOnce installer?
• Shortcut error
• No Touch Deployment and DTS
• Build Clickonce deliverables once and Deployed universally - Help please
• ClickOnce Installation -
• Cant return a value/data from a form called/shown from Main form
• How to override one Clickonce application entry in Start menu with other
• clickOnce downloading small updates not the entire application