It would be great to get some feedback on this, I've wasted nearly the whole day trying to figure it out.
I've created a simple test database called test.sdf. It contains a few tables but no data. My plan is to populate the database programatically; however, the INSERT command does not seem to be working correctly. I can see that the data actually gets added to the database when I add it and iterate over it programatically (using SqlCeCommands), but after the program completes and I look at the Table in "Server Explorer" via VS 2005, the data is no longer there!
Now note that the location of the sdf is in the Emulator's "shared folder." I have read from other posts (http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=173589&SiteID=1) that you cannot create a database on emulated "storage card" with PPC 2005 emulators but I've read nothing about modifying a database which exists there. Unfortunately I do not currently have access to a "real" device so I can't test this in any other way.
Here's the test function:
public
void Test(){
SqlCeConnection conn = null;
try
{
conn = new SqlCeConnection();
conn.ConnectionString = @"Data Source = \Storage Card\test.sdf";
conn.Open();
SqlCeCommand cmd1 = conn.CreateCommand();
cmd1.CommandText = "INSERT INTO Customers VALUES ('Joe Schmoe')";
int n = cmd1.ExecuteNonQuery();
cmd1.CommandText = "INSERT INTO Customers VALUES ('Alice Wonderland')";
n = cmd1.ExecuteNonQuery();
SqlCeCommand cmd2 = conn.CreateCommand();
cmd2.CommandText = "SELECT * FROM Customers";
SqlCeDataReader rdr = cmd2.ExecuteReader();
//this correctly prints out Joe Schmoe and Alice Wonderland
while (rdr.Read())
{
String str = rdr.GetString(0);
Console.WriteLine(str);
}
rdr.Close();
}
finally
{
conn.Close();
}
}
After running this test function, I open the Customers table in VS2005 and no Customer rows exist despite the fact that the SqlCeDataReader correctly iterated through the previously added 2 customers.

INSERT Not Working via Emulator SmartPhone WM 5.0
sladoid
Darren,
Thanks for the response. I am not certain how to place files in another folder besides the "storage card" in the emulator. This is always how I've been able to access input files (not database related) in the past. I open the emulator, click File->Configure and then set my shared folder to be the directory with my input files--which, in this case, also contains my test.sdf file. How would I copy my test.sdf over in a different manner like you are suggesting
j
vbmon
A couple of options available to you:
1. include the actual test.sdf file into your Compact Framework app. set the Build Action to Content and Copy to Output Directory = Always (or Copy if Newer). When you build and deploy to the SP emulator, the test.sdf file will automatically be placed in the program files\{app name} folder
-or-
2. start the emulator and then use the Device Emulator Manager to Cradle the emulated SP. Once ActiveSync connects, you can browse the filesystem of the emulator and move the file by hand.
Darren
awm129
Jon,
What happens if you place the test.sdf file in another folder other than the storage card in the emulator SQL Mobile does distinguish between storage cards and main memory in it's storage engine, so perhaps there is something going on related to your use of an emulated storage card.
Darren
madhan
esteth
That did it Darren, thank you very much. The changes I make programatically are actually being reflected in the database itself now.
j