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: , ,

Monday, March 09, 2009

Implementing visual inheritance in windows mobile

We've been working on a Windows Mobile 6 PDA application and one requirement is to have a status bar that shows internet connectivity and updates.

In Windows programming, a common way to do this is to create a base form which has a status bar and a mechanism to update it, this form is then used as a template for other forms. This means that you have a single point of failure, update and maintenance. This is a good thing as if you added that status bar to all your forms, you'd increase your maintenance headache with each new form.

On Windows Mobile, there is support for the same visual templating mechanism, but there are a few pitfalls. If for example on your base form you wanted to add a popup keyboard, you'd need to add a reference to Microsoft.WindowsCE.Forms. This unfortunately breaks the visual inheritance in Visual Studio's form designer saying "Visual inheritance is currently disabled", this also occurs when using Platform Invoke (a method of calling methods in the base operating system) in the base form.

Luckily there are a few workarounds for this:

Add a class diagram, select your base form, add a custom attribute of DesktopCompatible(true), this adds an XML Metadata Attribute file (.xmta).The xmta file can cause a genasm.exe error, ensure the build action is set to None and the copy to output directory is set to Do not copy, this should now build fine.


Job done, we have visual inheritance visible in the designer.

Labels: , , ,