Scenario: Iinserted or updated records from query analyzer to local Mobile database (sample.sdf) were preserved in permanently. If I insert, update or delete records from application using basic insert/update statements, inserted/updated records are loading to grid still I close the application. Every time execute non-query get succeeded and non query returning number of records inserted or else.
Problem: Once I restart application, I couldn't see the inserted/updated records on application display grid. Then I came to know that inserted, updated, and deleted records from my application were not preserved in mobile database (.sdf database attached to solution explorer and add to solution by selecting add -> SQL Mobile database from the list of items). This one I am testing on emulator, application running on my laptop, still I haven't deploy to device. Please suggest me what could be the probelm or mistake made by me, possible send web reference. I would appreciate your reply.
I have written basic insert statement to test, Please take a look at and suggest any issues
using (System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection("Data Source =\".\\Samples.sdf\""))
{
using (System.Data.SqlServerCe.SqlCeCommand cmd = new System.Data.SqlServerCe.SqlCeCommand("insert into sample(name,loc,CallStatus)values('xx','Peoria','open')"))
{
cmd.Connection = con;
con.Open();
int rval = cmd.ExecuteNonQuery();
con.Close();
}
}
Thanks,

Inserted/updated/deleted records from application were not preserved permanently in Mobile database, .sdf file?
George2
Yes, you can use that as well, it maps desktop folder on to simulated storage card.
Make sure you don't run SDF file from it though; I believe there's a bug in emulator which would lead to a failure in SQL Mobile.
psc161
You can use RAPI to copy SDF from device to desktop programmatically. It's been answered about dozen times before, so please search if you need details.
If you need to do it manually during development, simply cradle the emulator and copy file using Active Sync.
m.a.fuchs
You are right. As you said when ever I run application database (.sdf) coping to Debug directory, thats reason I Could not see the changes. I set .sdf propery "copy to output directory :do not copy" and I copied .sdf database file to Debug Folder. so its using the same file, instead of loading evertime. I guess we can also copy back .sdf from output directory to local/required location, so every time changes can be viewed. This I tested on standalone application, I belive it works same way on emultor. I am going to test the same on emulator. Thanks a lot for helping me. any suggestions
Thanks,
JinMengcheng
Thanks, I will try using RAPI. There is another way to do manually, In VS.NET tool device options, set the path of Shared Folder, ex: C:\Documents and Settings\GSReddy\My Documents\My Pictures\DeviceStorageCard. when ever save state of emulator, all files/Folders including database,application exe etc. copied to shared folder path, which is on laptop hard drive. I guess shared path like storage card.
Thanks,
Radith
it seems I can't attach code snippet to the post. if I give connection string like below, its working else not. is it right, plz suggest
con.ConnectionString = ("Data Source =" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + \\AppDatabaseCallInfo.sdf;));
BirDene
although I run application on emulator, database changes overwrite every time At least last inserted records should be in database, but I dont see even a single record in database.
Please let me know, How to disable VS deployment.
Thanks,
MotteKarotte
Sure, VS does not care if you run on emulator or not, it would redeploy files regardless. In fact, it's even more likely with emulator as you might forget to save the emulator's state which means all changes automatically lost. There will be no changes, not last not first as changes database is simply deleted.
To find out how to configure deployment options for any file (including database file) in VS project, hit F1 in VS and type “file properties” in search box. After you set it correctly, make sure you’re saving emulator state or your changes will be lost anyway.
cheesenhomer
VS.NET is redeploying database every time on to emulator, I change database file option copy to o/p directory: Do not copy. Now its working okay and I am able to view all the records.
As part of sync how can I move the .sdf file from emulator memory to hard drive location I am able to see database file in emulator under \programs\FileExplorer\<database.sdf & app exe>, it is possible only on device. plz suggest.
Thanks,
Alexander Marinov
Emulator’s changes can be saved programmatically or when close emulator it prompts user to save State. I tried by using save state menu item; I am able to see the inserted records for just couple of seconds, then its loading default records from database. It seems to be loading records from database again. Do I need to install database file to smilator something or vice versa. if you get some time, you can take a look at attached small snippet, suggest the solution plz.
BrunoAMSilva
If you have SDF file in your project, VS would redeploy it every time you restart the application.
That would overwrite changed copy on your device and all changes will be lost. Either disable VS deployment or copy database back from device to desktop each time you change it.
Bill YU
Emulator's state is saved as you close it, it's not possible to do programmatically. You should realize emulator is not using your desktop file system, it does not see or use your database on desktop's file system. It works with a copy on emulated file system instead. That copy and everything in it is destroyed every time you restart the emulator (unless you save state – state includes emulator’s file system) or every time you restart your project in VS (unless you disabled database file deployment via file properties). Your code is irrelevant to the issue.
It seems like you do not understand what's going on, allow me to clarify the scenario on desktop example:
1. You have database on CD.
2. You copy it from CD to desktop.
3. You change database on desktop.
4. You copy database from CD to desktop on top of your changed database (and reformat your desktop’s hard drive and reinstall your OS from scratch before that – in case you don’t save the emulator’s state).
5. Naturally all your changes are gone and database on CD is not altered in any way.