Another area that you might want to probe into is whether or not your database tables are updated correctly. SQL Server CE 2.0 comes with a tool known as the SQL Server CE Query Analyzer. The first time you run an application with the SQL Server CE Managed Provider referenced, the SDE will copy the relevant files to the target device (or emulator). The SQL Server CE Query Analyzer can then be invoked by clicking Start->SQLCE Query (as shown in Figure 10).
Figure 10: Using the SQL Server CE Query Analyzer
To connect to a SQL Server CE database, click on the button shown with a green arrow and a cylinder.
Figure 11: Connecting to a SQL Server CE database
You can either connect to an existing database or create a new one. For this article, I will show how we can examine the database that we have created earlier.Figure 12 shows the tables and fields of the database that we created earlier:
Figure 12: Examining the BookStores.sdf database
To retrieve the records in the tables, you can use SQL statements under the SQL tab and examine the results under the Grid tab:
Figure 13: Using SQL Statements and examining the results
A nice feature of the Query Analyzer is the "Button Presets" function. The Button Presets function allows you to store commonly used SQL statements so that they can be invoked by simply clicking on the preset buttons (labeled 1-10).
Figure 14: Using the Preset button for storing commonly used SQL statements
Resetting the Emulator
There are times when the Query Analyzer simply refuses to work, perhaps due to the beta nature of this product. In most cases, doing a soft reset on the emulator can solve the problem. A soft reset does not erase the database stored in it. However, a hard reset will wipe out the database, as well as the Query Analyzer. The only way to get it back is to run the application in Visual Studio .NET again (as the database needs to be recreated).
Opening and Closing
You may also notice that the application opens and closes database connections before and after each operation. I found that, in the current beta, the emulator would crash if the connection was left open when the application exits.
In this article, we have seen how to use the SDE to create a simple Pocket PC application to consume a Web service, and how information can be stored locally using the SQL Server CE Edition 2. One problem exists: how do you synchronize the data on the Pocket PC to your desktop? In the next article, I will discuss how data stored in SQL Server CE can be replicated and synchronized with a SQL Server database. Till then, have fun!
About the Author
Wei-Meng Lee is an author and developer specializing in .NET. He has co-authored many books on XML and mobile application development. Wei-Meng is also a contributing author to SQL Server Magazine, Visual Studio Magazine, and .NET Magazine. Contact Wei-Meng at firstname.lastname@example.org.
Sample code for this article can be downloaded here. (603K zip)
Return to the .NET DevCenter