Persistence problem

Nov 17, 2010 at 8:22 PM

I am implementing the Sterling DB for use with a Windows Phone 7 app.  All is going well except for one major problem: whilst the app is running I can store and retrieve data without a problem.

However, when I restart the application (with the emulator still running), the data appears to be gone. What am I missing here?



Nov 18, 2010 at 2:54 PM

You should try to call the Flush() method on your database instance. This should serialize everything that's not been serialized.

Nov 18, 2010 at 7:23 PM

Thanks Tehashix!  That worked fine. I was not aware of the Flush() method.  Next issue will be to define the best design for calling Flush() in terms of Serializing / DeSerializing in the most appropriate manner.

Thanks again!

Nov 18, 2010 at 11:14 PM

I gave an example on the Windows phone that works with deactivation - but the problem is when you stop the debugger cold, it never calls those. The best practice there is to call flush after any insert or delete - while the entities are persisted immediately, it's the keys and indexes that are cached but Sterling is smart enough to only serialize the ones that have changed when you call flush.

Mar 21, 2011 at 11:12 AM

I called flush method after insert.

After restarting my emulator, the values are gone. I am wondering if this is happening only with emulator or will it be the same on a device?

Mar 21, 2011 at 11:37 AM

Anytime you rebuild or restart the emulator, isolated storage is cleared. If you leave the emulator up and just use build (not rebuild) it should be there between sessions. It doesn not work the same way on an actual device.

Mar 21, 2011 at 12:13 PM

So I only need to save the values once (this is the first time application run) and then I get the values automatically?

Mar 21, 2011 at 12:16 PM

The user's guide provides many examples of setting it up and then querying/loading data - if you haven't read through it yet, I highly recommend started there:

Mar 22, 2011 at 4:58 PM

Is my understanding correct?

I have some text files and I need to parse some data to get useful values to store them to my sterling database. When a user installs my program his isolated storage for that app will be empty. That's why the parsing will occurr and fill the database with values. Next time the same app starts, the database will be full so the parsing will not occur again. Actually, it will not occur ever again since the database (in isolated storage) is already filled.

In case of using emulator there is always need to fill the database first since the isolated storage is cleared after each restart.

Thanks for any explanation.

Mar 22, 2011 at 5:11 PM

Correct. Common strategy is to either persist a setting into application settings or to save a value to a file at the very end of the process.

The logic becomes:

1. Is my special value there?

2. Yes - great, database is populated, business as usual

3. Nope - OK, load up the database

4. Last step after loading up the databes, set my special value

In the emulator if you rebuild or close and open then yes, you'll end up in steps 3 - 4.

Mar 22, 2011 at 5:21 PM

Oh great. Looks like IsolatedStorageSettings will store information about the state of my database.

Thanks for pointing that out.