Hi
How I can work with sqlCE (sdf Files) in PPC (windows mobile) Emulator ?
(The Visual studio 2008 emulator)
thank's in advance
Hi
How I can work with sqlCE (sdf Files) in PPC (windows mobile) Emulator ?
(The Visual studio 2008 emulator)
thank's in advance
If you go to Start->Programs->Visual Studio 20XX-> Visual Studio Remote Tools, there's a program called Remote Viewer. When you launch that, you can see the "file system" of your virtual device. Just transfer the SDF file to somewhere on the file system, and set your connection string in your app to that location.
EDIT: Just to be a bit more clear, I'll run you through a quick sample. Open Remote Viewer (make sure you're using the same device type like the one in your project) and find the ApplicationData folder. Then, click File-> Export File and navigate to your C:/Program Files/Microsoft Sql Server Compact Edition/V3.5/Samples and select the Northwind.sdf. This will transfer the Northwind db to your virtual device.
Then, go to your project and create a simple form with a button and a DataGrid. Then, click Add Reference, and add a reference to System.Data.SqlServerCe. Then, add this code in your button1 click event:
private void button1_Click(object sender, EventArgs e)
{
string connectionString = String.Format(@"Data Source={0}\Northwind.sdf",
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
SqlCeConnection connection = new SqlCeConnection(connectionString);
DataTable table = new DataTable();
SqlCeDataAdapter adapter = new SqlCeDataAdapter("SELECT * FROM PRODUCTS",connection);
adapter.Fill(table);
this.dataGrid1.DataSource = table;
}
Run it and click the button. Good luck!
As a separate storage option, open the Emulator, then click File -> Configure. You'll see a textbox that is labeled "Shared Folder". Set that to any folder on your desktop PC. The emulator will then "mount" that folder on your PC as a folder in the emulator called "Storage Card".
Do you want something running on the device that enables you to interact with the database directly?
Or do you want to use desktop tools to interact with a database also visible by the emulator?
In the first case you could install SQL Server Compact Query Analyzer (http://msdn.microsoft.com/en-us/library/ms172926.aspx). This tool enables you to query and alter the structure of *.SDF files directly on the PDA.
In the second case Visual Studio 2008 or SQL Server Management Studio 2008 should both be able to directly connect to your emulator (if you cradle it via ActiveSync first).
BFree, thank you so much for that answer using the remote file viewer. I'm new to windows mobile programming, and it literally took me an hour or more to get my connection string correct, because I had no idea the emulator would look at the device's structure. It makes perfect sense why it would do that now, but again, I'm still learning. I kept finding references to using its own structure and you can't reference C:\ or anything like that, but no one would tell WHAT TO DO! It was such a relief that you gave the solution along with the description, so thank you very much, it worked in about 2 minutes after I read your post!
Thanks! Paul