Database gets deleted when Project is Rebuilt and deployed while debugging

Dec 17, 2010 at 5:49 AM

Hi,

I use the following code to check for database existence before creating a new one:

//check if the database exists
if (false == Database.DoesDatabaseExists(Constants.strDBName))
{
   //create new database
   objDB = Database.CreateDatabase(Constants.strDBName);
   objDB.Save();

   //store the required predefined SMS data
   DBFunctions.createAndFillSMSTable(objDB);

   objDB.Save();
}   
else
{
   objDB = Database.OpenDatabase(Constants.strDBName);
}


public static void createAndFillSMSTable(Database objDB)
{     
   objDB.CreateTable<smstable>();
   objDB.Table<smstable>().Add(new smstable("Congratulations!"));
   objDB.Save();
}


I am facing the following problem:

1. When I am dubugging the application and abruptly stop the execution (by pressing shift+ F5 in VS 2010), On next launch of the application ,
The database will not be available. It creates a new database.
2. Between such Debug cycles, Many a times I faced this problem. Not able to figure out what is going wrong. I am calling Save() function also
everywhere I change something.
3. I do not see this problem when I launch the application from Phone (When I am not debugging).

Any idea what would be wrong?
I am testing the application on real device.(FYI).

Thanks.
Himanshu

Dec 17, 2010 at 9:04 AM

Hi,

There is an update.

I came to know that the Database gets deleted only when I Rebuild the Project and then Deploy it for debugging on the Device.

Has anybody come across this issue?

Is this the normal behavior of the Isolated Storage or there is some issue?

Please help.

Himanshu.

 

Dec 18, 2010 at 2:50 PM

Emulator is essentially a read-only environment, so no changes survive if you restart the emulator.  I think this is what you are running into.

Dec 18, 2010 at 5:27 PM

Hi,

SergeyBarskiy,

Thanks for the reply.

I am aware of this behavior of the Emulator. But I am testing on Real device, not an emulator and I am not restarting the device.

I get this problem only when I rebuild my project and deploy it to device for debug. If I do not Rebuild, I can debug the application any number of times without any problem.

When I Rebuild and deploy the application , Device takes little more time to launch the application every time compared to non-rebuild version and at that time, It creates new Database.

I suspect this is the behavior of the Isolated Storage, but was not able to get confirmation from any reliable source.

I just wanted to find out where the problem lies. Is it with the database or the Isolated Storage? Till now I have not got any help on this behavior. The behavior is pretty consistent.

Are you aware of any such problems?

Please post if you come to know of anything .

Thanks again.

Himanshu

 

Dec 18, 2010 at 9:58 PM

Unfortunately, I am not aware of what is causing this. My guess is that rebuild/deploy will redeploy application from scratch. To be consistent, this process should wipe any remnants of the application off the device. I am thinking this is why you see the symptoms. Also, if you would like, you can post this on phone 7 forums to see if someone from the team can answer this for you more definitively.

 Sergey

Jan 3, 2011 at 3:03 PM

Dear Himanshu,

I would like to know whether you have resolved the problem. And how?

I am making a WP7 application, but unfortunately I still do not have a device in order to test it on a device.

Is this a case when you restart your phone that you lose the whole data in the database, or when you update the application the database is empty or?

I could not make diffierence between the terms  rebuild and deploy.

Thanks in advance.

Bosilkovska

Jan 3, 2011 at 4:15 PM

Hi,

bosilkovska,

The problem I described above does not seem to be a problem at all.

As I found out, Windows Phone wipes out the application's Isolated Storage when you Rebuild your application. (Rebuild here means right clicking on the project and selecting "Rebuild" from the menu.)

So When you deploy or debug the application again on device ( by pressing F5) after "Rebuild", the things you saved in isolated storage will not be present anymore since they are deleted.

This occurs only when you "Rebuild" your application. The normal "Build" option does not wipe out the Isolated Storage.  However, without "Rebuilding" the application, you can run your application how much ever you want without any problem.

This seems to be a normal behavior with the Isolated Storage.

Restarting the phone or any other action does not affect Iso Storage.

See the below link of Phone 7 forum where I posted the above problem:

http://forums.create.msdn.com/forums/t/69877.aspx

Hope this helps.

Himanshu