The following application shows a subtle difference in dealing with enums using Enum class methods and when using reflection. In this sample, I am looking to find the number of elements in the enum. Enum.GetValues
are not implemented in the .NET Compact Framework, so I cannot use those methods.
By using reflection, I figured I would gain the upper hand and take control of my enum woes. Unfortunately, calling GetFields on an enum type adds an extra entry named "value__" to the returned list. After browsing through the decompilation of Enum, I found that value__ is just a special instance field used by the enum to hold the value of the selected member. I also noticed that the actual enum members are really marked as static. So, to get around this problem, all you need to do is call GetFields with the BindingFlags set to only retrieve the public, static fields (see the code example below).
static void Main(string args)
Type enumType = typeof(Test);
//The following prints 3, but we can't use this method in .NET CF
infos = enumType.GetFields();
//The following prints 4! There is an extra, unrelated Int32 entry named "value__"
//at the zeroth element of the info array.
//The following prints the 3 enum elements. The value__ field is removed by
//specifying we only want the public, static fields.
infos = enumType.GetFields(BindingFlags.Public | BindingFlags.Static);
foreach (FieldInfo fi in infos)
I just went through the very lengthy process of moving from MSSQLCE beta to MSSQLCE release. The good news is that after I was done, all of my code still worked, so at least I have that going for me.
The biggest time sink for me was uninstalling applications. Uninstalling the patch from VS2005 Pro was not all that straight-forward. First, I had to re-download and burn the ISO image since I couldn't find my original DVD. I then noticed that I had another entry in my Add/Remove Programs called "Microsoft Visual Studio 2005 Permier Partner Edition - ENU" that had the VS.NET SP1 Beta applied to it. I had no idea how this program got installed, and that took quite a bit of spelunking to figure out. I came across a blog entry from Heath Stewart that explained how to look into the patch database to figure out which MS patches were applied to which products. After installing that, it needed a Windows Installer Patch (msp) file, but I couldn't find that. I ended up searching my system, and got the VS.NET msp file and opened it in Heath's utility. From there, I got the GUID of the Premier Partner Edition, and searched my registry. In the end, it turned out to be MSSQL 2005 Developer Edition that installed that program. I finally located that DVD, pointed the uninstaller to the right msi file, and I was able to uninstall the patch. However, after completing all of this, I couldn't install the MSSQL Server 2005 Compact Edition Tools for VS 2005 SP1. I received the same error as I did last time (see the above link for details), but I couldn't solve it by doing a Repair on VS.NET, and I couldn't dig anything up in Filemon or Regmon to find out why it was failing so I ended up completely uninstalling and reinstalling VS.NET. Not exactly very user-friendly.
Installing the release of MSSQLCE is very similar to the post I made earlier on how to install MSSQLCE. The difference is the links to the new files, which can be found here:
When John Kaster
of CodeGear (formerly Borland) came to Milwaukee last year, he showed a demo of some software running on a Pocket PC (PPC). The cool part was he was working on the actual PPC device itself but broadcasting the PPC screen to the overhead projector through his laptop.
I checked with him this week as I'm doing more work in this area now, and he told me that the free tool to get this done is called ActiveSync Remote Display. It is part of the Windows Mobile Developer Power Toys, available from Microsoft. I also tested it this week, and I can report that it still works with Active Sync 4.2.
Rory Blyth has a couple of good videos on MSDN TV, showing how to use MSSQL Mobile Edition on a CF device. They are older, so they don't cover all the new nomenclature (and probably newer features), but there are a couple of good tips and tricks in there, and it contains good coverage of Remote Data Access
, a technology that will help synchronize data to/from MSSQL Compact Edition.
Here's my experience getting this combination of tools to work properly. At times, it was extremely frustrating, and other times it was confusing. MS has not helped much what with obsolete, out-dated, mis-named, and near impossible to find products. Hopefully the RTM version will have everything stitched together nicely so all you have to do is double click a setup file. It would be even better to have log information easily and readily available for the installs. If you want to develop with these technologies, give these steps a try. I don't claim that they are authoritatve or complete, but I documented as much as I could capture.
- ActiveSync Setup 4.2 - required for several other installs later on.
- Windows Mobile 5.0 PPC SDK - adds new platform targets and emulators to support PPC development with WM 5.0. There is also a Windows Mobile 5.0 SDK for Smartphone download available if you prefer that instead.
- VS.NET 2005 SP1 Beta - I couldn't get to this page from the MS site anywhere, but I was able to find a link to take me to the download location. I can't swear that this is entirely required, as I installed the other tools without it on one PC, and it seemed to work OK.
- Microsoft SQL Server 2005 Everywhere Edition Tools for Visual Studio 2005 Service Pack 1 Beta - This install specifically states that VS.NET SP1 Beta is required. As you can see from the title, it also mentions SqlServer Everywhere, but ignore that inconsistency. The MSSQL team has renamed the product to SQL Server Compact Edition. This naming problem is supposed to be fixed by the time MS releases MSSQL Compact Edition.
I also ran into a problem when uninstalling this application. I would get the following error when trying to reinstall it:
The upgrade patch cannot be installed by the Windows Installer service
because the program to be upgraded may be missing, or the upgrade path
may update a different version of the program. Verify that the program
to be upgraded exists on your computer and that you have the correct
I finally did a Repair install on VS.NET, and I was able to install the tools again.
However, even with all of that, I would recommend installing this because it allows for things like Server Explorer to be used on SDF files.
- Microsoft SQL Server 2005 Compact Edition RC1 - This installs MSSQL Compact Edition. Note that there are numerous naming changes throughout the web (Mobile, Everywhere, Compact), but Compact Edition is going to be the final answer - allegedly.
- Windows Mobile 5.0 SDK for Pocket PC - This install will give you some more power within the IDE, e.g. it will bring up the Data Configuration Wizard to generate DataSets when adding an SDF to your project. It also installs the latest version of Northwind.sdf for you to play with. By default, it gets installed to C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\northwind.sdf.
- (Semi-optional) SQL Server 2005 Compact Edition Books Online Community Technology Preview (CTP) - Reference information is always good, right?
- You can manage an SDF file from your desktop machine, by using Server Explorer within VS.NET, or by selecting SQL Server Mobile as the Database Type in SQL Server Management Studio. On the PPC device, you can use QueryAnalyzer (located at /Program Files/SQL Mobile/EN/isqlw30.exe), or open the sdf file on the PPC device.
- To deploy an SDF to the PPC, just add it to your solution and it will get deployed to the PPC device automatically.
Good luck, and I hope this helps someone through the corn field maze that is CF and MSSQL CE installation.
I've been working on a .NET Compact Framework (CF) 2.0 application, and one thing that this applciation needed was access to a local database on the PDA. In addition, I was hoping to leverage some of the MS Application Blocks, specifically the Data Access Application Block, to make things easier and more uniform for the developers.
I came across a library that ported the .NET 1.1 version of the Data Access Application Block to CF: Data Access Application Block for .NET CF. It was pretty good, but there were several things that needed fixing for my situation, namely: removal of OpenNetCF, upgrade to .NET CF 2.0, upgrade to Windows Mobile 5.0, and upgrade of the Northwind.sdf database to the latest version provided by Microsoft.
Here is my port of the original work. I'll post updates (like upgrades to Enterprise Library for .NET Framework 2.0, January 2006) to the blog here, and my web site.