Compsoft Flexible Specialists

Compsoft plc

Compsoft Weblog Compsoft Website News Archive Privacy Policy Contact Us  

Monday, May 18, 2009

Combatting "Unspecified error"

In one of our Windows Mobile applications we've been noticing some bizarre exceptions where we're logging a rare exception of "Unspecified Error".

It's always a pain getting this kind of error, you really have no clue where to turn. Pin pointing the general area and finding the point at which the application fails tends to be the only route and led us to find it was database related.

Further research into the error implies that the issue lies in SQL CE (we're using SQL CE 3.5 SP1). It's at the point we're touching the database but ONLY after the device has come out of stand by mode and ONLY if the database file is located on the storage / memory card. Database files stored on the internal memory are fine.

It turns out that the SQL Server Mobile engine has a bug when the database file is accessed before the block device driver (that allows you to access the database file) has started up after the device is restored from suspend mode.

There's a hotfix available for previous versions but not the latest and it only seems to give a more intelligible error message of "The disk is not ready" or "The OS storage system (RAM, CF, SD, or IPSM) is not responding. Retry the operation".

Which leaves us with the choice of what to do in this instance.

1. Handle database access exceptions until the device is ready again.

2. Wire up to the device's power events and handle the Power up event.

3. Move the database file to the Internal memory.

I decided to go with option 2. A significant amount of work would have been required for option 1. The devices we're working against have a 2GB storage card versus a 64mb internal memory so I felt this wouldn't work for us without impacting performance so I didn't go for option 3.

The easiest way to go with option 2 is by using the opennetcf smart device framework framework which in the OpenNETCF.WindowsCE.PowerManagement namespace allows you to wire up to all the Power related states and their changes.

Here's one possible solution:

   1: static void Main()
   2: {
   3:     OpenNETCF.WindowsCE.PowerManagement.PowerUp += new 
OpenNETCF.WindowsCE.DeviceNotification(PowerManagement_PowerUp);
   4:     //Run the app
   5: }
   6:  
   7: private static void PowerManagement_PowerUp()
   8: {
   9:     System.Windows.Forms.Application.Exit();
  10: }

OpenNetCF has some great products, their download count is at 3/4 million at the time of writing. They have good customer service too.

Labels: , ,

0 Comments:

Post a Comment

<< Home