DEVBUZZ Homepage SQLCEDBView
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | .NET Compact Framework

SQLCEDBView
Written by Michael Gledhill  [author's bio]  [read 20367 times]
Edited by Derek

SQL Server CE 2.0   

Page 1  Page 2  Page 3  Page 4  Page 5 

Of course, usually, the SQL queries that you'll run on your SQLCE databases are going to be a little more complicated than the example we just used:

UPDATE employees SET City='Toronto' WHERE EmployeeID=2

Usually, the record you'll want to UPDATE will depend on a record or item you've clicked on on the device, the INSERT will depend on data you've entered, and so on.  It's hardly surprising that by the time you've put together an SQL command to run, there might be errors in it.

The bad news: I can't fix your SQL bugs for you.  Sorry.  I've already got my own collection of bugs to fix, thanks...!

The good news: Using the following tips, you can constantly view, on your Desktop, the last SQL statement that was run on your device. And, trust me, when an error occurs, having a window on your desktop showing that you've just run an incorrect SQL command:

UPDATE employeesSET City=Toronto WHERE EmployeeID=2

is a lot easier than trying to interpret those vague .Net exception errors on the device.

Suggestion 2

Remember I told you how SQLCE Database Viewer allows you to choose how each type of file will be opened: either on the device or on your Desktop ? Well, there's a third option, to open the file using the built-in text editor.

Don't get excited, I haven't written a full-blown text editor.  This is a very simple ASCII/UNICODE text-file editor, with two Pocket PC friendly features:

  • When you click on File\Save, it saves the file straight back to your device.
  • Every few seconds, the device's copy of the file is checked. If it's been updated on the device, it's contents will be refreshed (reloaded) on the Desktop.

So now, we can add a few lines of code to our "Run some SQL" function, which will save the SQL command to a simple one-line text file on the device.  Then, on our Desktop, we'll keep this text file open in "SQLCE Database Viewer", and we'll constantly have a dispay of the last SQL command that was run.

using System.IO;

public void WriteSQLtofile(string SQLcmd)
{
    StreamWriter sw;
    sw = new StreamWriter("\\My Documents\\SQL.txt");
    sw.Write(SQLcmd);
    sw.Close();
}

private void RunSQL(string SQLcmd)
{
#if DEBUG
    // In DEBUG mode (only), open up the connection to the
    // SQLCE database each time we run an SQL command.
    SqlCeConnection m_conn;
    m_conn = new SqlCeConnection(connectionString);
    m_conn.Open();

    WriteSQLtofile(SQLcmd);
#else
    // In Release mode, we'll use a Global SqlCeConnection
    // variable for an SQLCE connection that'll always
    // be kept open.
#endif

    ... (etc)
}

As promised, when we run an invalid SQL command in our .Net CF program, it'll still throw an exception, but within a few seconds, our text-editor program refreshes itself and shows us the SQL that caused the problem:

The eagle-eyed amongst you will have noticed it's even "cleaned up" that SQL statement - that single-line SQL statement has been split up into five lines - making it easier to read.  This is just done for clarity (and is a lifesaver when your SQL statements start getting complicated), and can be turned off using the "Tidy it up for me!" checkbox.

Needless to say, you could take this further, perhaps changing your exception handler code to write the SQL error description to a different file.

This function becomes invaluable when you are testing your application. Supposing you're running your .Net CF application, and are busy adding a new record. You hit your Save button to save your changes, and straightaway, you get to see the SQL INSERT command that's being run on your database.

Previous Page  Next Page 

Back to .NET Compact Framework | [Article Index]

 

Back to the top of the page.
Franson GPS tools for the Pocket PC Chris De Herrera's Windows CE Website Windows CE News & Information Source RESCO Software discounts
Copyright ©2000-2008 by DEVBUZZ.COM, Inc., TX. USA.