DatabaseSchemaUpdater Error in WP7

I implemented some db versioning logic with DatabaseSchemaUpdater and found one problem.

If I execute this code

updater.DatabaseSchemaVersion = updater.DatabaseSchemaVersion + new Random().Next(10)+1; updater.Execute(); 

and leave a request with the back button - everything is in order. Changed version of the scheme.

If I leave the Start button, and then run the application again (in my opinion, a fairly common case for a regular user) - nothing is updated. Db has a previous version.

calling Dispose () will fix this problem, but we are using the Singleton DataContext object, so this approach will be a little hacked for this case.

https://www.dropbox.com/s/wfyvwvjd12wifgl/DBUpdTest.zip - test project - you can just launch the application and close it in different ways and see what happens (db ver is written in text boxes).

Questions: Is this normal? Does deactivating and launching the application again violate something else? Is there any way around such things (except for Disposing)?

+4
source share
3 answers

I had the same problem in the last two hours and I searched a lot on Google. The only solution that helped me was to actually use the using keyword in the database context. Right after that I recreated the data context.

 // _dataContext is static. By checking for null I make sure that the database // creation and migration is only done once during the app lifecycle if (_dataContext == null) { // get the context using (_dataContext = new WorkTimesDataContext(IsoStoreDatabasefile)) { // do DB creation // do DB migration } // now that the context is disposed, recreate it _dataContext = new WorkTimesDataContext(IsoStoreDatabasefile); } 

It seems that the database is not updated correctly when the application enters the tombstone state, although the official documentation clearly states: "When this method is called (" Execution "), all changes are sent to the local database as a single transaction , including version updates .

+2
source

your tombstone is missing, which will allow you to back up data in isolated storage.

This is very necessary when working with data on a Windows phone. The link below should be sufficient to talk about how it works and how easy it is to implement in your application.

Video covers

0
source

I had the same problem because I had a beta version of the WP7 SDK. He fixed himself after installing a non-beta version.

0
source

Source: https://habr.com/ru/post/1380807/


All Articles