Question

I have a ClickOnce application with a *.sdf file that I'm using as a database. Each user will have a local database. I want to be sure that when I deploy a new update to my application, the user doesn't lose any data in his local database.

I ran a simple test and it seems to be the case that database records are saved between application updates. I checked the database connection string however, and the *.sdf file that the application uses is different between updates. It looks like the *.sdf file resides in a temporary folder:

Version 1: C:\Users\username\AppData\Local\Apps\2.0\Data\BTC7847T.TGN\
  RX0XEL7T.28C\db_v..tion_5b84da8ac499fbd9_0001.0000_218dbb369a32672c\Data\db.sdf

Version 2: C:\Users\username\AppData\Local\Apps\2.0\Data\BTC7847T.TGN\
  RX0XEL7T.28C\db_v..tion_5b84da8ac499fbd9_0001.0000_228bdaad95bad96c\Data\db.sdf

These folder paths are not the same, but the data in the *.sdf files is the same. Is this some coincidence? Or can I be assured that users will not lose data between application updates?

Was it helpful?

Solution

Since I see C:\Users\username\AppData\Local\..., I guess the .sdf file is marked as Data file.

From How ClickOnce Performs Application Updates and Accessing Local and Remote Data in ClickOnce Applications (Data Directory and Application versions) on MSDN:

Each version of an application has its own Data Directory, which is isolated from other versions. (...) When a new version of an application is installed, ClickOnce will copy all the existing data files from the previous version's Data Directory into the new version's Data Directory—whether they were included in the original deployment or created by the application.

ClickOnce will replace the older version of the file with the newer version of the server if a data file has a different hash value in the old version of the application as in the new version.

It means that if .sdf does not change you will not loose data, the file will be copied (just the path of the file will change since the Data Directory changes).

Also, if the earlier version of the application created a new file that has the same name as a file included in the new version's deployment, ClickOnce will overwrite the old version's file with the new file. In both cases, the old files will be included in a subdirectory inside the data directory named .pre, so that the application can still access the old data for migration purposes.

Not tested but it means that you can still access the previous user data, if the .sdf source has changes and is recreated on client.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top