When developing mobile applications using Compact Framework and storing data to the local device database it is very handy to be able to debug and test sql queries direct on the device. This post will walk you through how to connect to the device DB, look at the tables in the device DB and run SQL queries on the device DB.
Run your application from Visual Studio, your device or emulator must be connected and cradled. (I’m running on Vista so I am using Windows Mobile Device Center).
You need to install Microsoft SQL server (I’m using the 2005 version) and run the Microsoft SQL server management studio.
Create a new connection with the following attributes:
- Server type: SQL Server Compact Edition
- Database file: Browse to your connected device DB path. This is found under Mobile Device –> Program files –> “Your application name” –> db –> “appname”.sdf
- Authentication: SQL Server Compact Edition Authentication
- Password: t1e23st4 (default password)
Click connect and a connection to your device DB should be established.
When connected you can chose to use the Object browser to browse the different tables and views.
The function I use most frequently is to write SQL queries and test them direct on the device DB before I add them in the application code. This is done by clicking on the New Query button and you can write your queries in the right side window. When you want to execute the query just click the Execute button and you will see the results from your query. It is also possible to save queries if you don’t want to write them again every single time.
This have saved me a lot of time and frustration