Restoring backup to WP7 Isolated storage

May 16, 2011 at 10:53 AM
Hi all, I have created a backup of a Sterling database on the desktop. This backup I include in a Windows Phone 7 application as a resource. When I want to restore the database to the isolated storage, I receive the following message: "Value does not fall within the expected range." I use the following code to restore the database: StreamResourceInfo sri = Application.GetResourceStream(new Uri("SterlingDatabase\\myDatabase.bak", UriKind.RelativeOrAbsolute)); if (sri != null) { BinaryReader brInput = new BinaryReader(sri.Stream); App.CurrentEngine.SterlingDatabase.Restore<SterlingDatabase.bdb_PDA>(brInput); App.CurrentEngine.Dispose(); App.CurrentEngine = new Wintellect.Sterling.SterlingEngine(); App.CurrentEngine.Activate(); App.CurrentEngine.SterlingDatabase.RegisterDatabase<SterlingDatabase.bdb_PDA>(); } The error is given at the line with the .Restore command. Does anybody have any idea what I'm doing wrong here? Many thanks.
Coordinator
May 16, 2011 at 11:05 AM

What version of Sterling are you using? If 1.0, did you follow the instructinos for copying the types.dat file over as well?

May 16, 2011 at 11:51 AM

I'm using the 1.0 version. I didn't copy the .dat file.

But as I can understand from the manual: "With a fresh install, you should restore the database, shut down the engine, then restore the type master (see above)..." I should first restore and then copy the type.dat. I can't get past the restore step without the mentioned exception.

I also tried to use the 1.4 beta, but after downloading the version in the downloaded package still states 1.0.0.0 in the bin files, altough the source solution says 1.4.0.0. Anyway, I get the same exception with the beta version.

Coordinator
May 16, 2011 at 11:56 AM

Again, the types.dat is the key I believe. For 1.0 you'll need to shut down the engine, restore the types.dat, THEN reactivate the engine. For 1.4 it shouldn't be an issue - I've tested this and the example solution for the desktop is an example (the generator generates the backup, and the restored image is what is used to run it).

May 16, 2011 at 12:45 PM

I tried to made a desktop example and it works fine. But on my windows phone 7 I still recieve the message "Value does not fall within the expected range" when I call the restore method.

Coordinator
May 16, 2011 at 12:46 PM

Hmmm - have you tried restoring the database/types.dat from the desktop example to the phone? Just curious. They share the same code base so not sure why there would be a difference, but I'll add it to the list of things to look into. Thanks!

May 17, 2011 at 10:40 AM

Hi,

I tested backup and restore database to my desktop and it works fine, but if I restore the database to my Windows Phone 7 I will always get the exception "Value does not fall within the expected range.", I also tested to restore your database backup from your desktop example to my phone and it's still failing when I call the restore method.

Is it possible to restore the database backup to the Windows Phone 7?

Or is there another way to deploy the sterling database to a Windows Phone 7?

Coordinator
May 17, 2011 at 10:45 AM

It should be possible and it should work, yes. What you are describing sounds like a bug. I'll have to look into it and let you know.

May 18, 2011 at 6:56 AM

I'm now looking for another approach.

I zip the desktop database and unzip it to isolated storage. I check that all the folders and files exists in isolated storage. So far so good.

The Sterling Database exists on the filesystem or isolated storage as a folder named with a number: 1229782093.

Now I want to attach this database, but when I do
_engine.SterlingDatabase.RegisterDatabase();
I assume that it will create a new folder with another number, another database.

How can I attach to the unzipped database with folder name eg. 1229782093?

May 18, 2011 at 7:27 AM

I read in the documentation that the root path should be named Sterling. Should I unzip to a folder sterling?

On the desktop application I get the following file structure:
LocalAppData\MyLocalApp\1229782093 (folder):
LocalAppData\MyLocalApp\1229782093\types.dat:
LocalAppData\MyLocalApp\1229782093\0 (folder):
LocalAppData\MyLocalApp\1229782093\0\0 (folder)
LocalAppData\MyLocalApp\1229782093\0\Keys.dat
LocalAppData\MyLocalApp\1229782093\0\0\0 (file)
LocalAppData\MyLocalApp\1229782093\0\0\1 (file)
LocalAppData\MyLocalApp\1229782093\0\0\2 (file)

When I do a register database on the phone, it create a "Sterling" folder database, but it seems that the internal file structure is different from the desktop file structure... Can you confirm that?