Thoughts from Dan Miser RSS 2.0
# Thursday, 22 March 2007
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 and Enum.GetNames 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).


using System;

using System.Reflection;

 

namespace EnumReflection

{

    class Program

    {

        enum Test

        {

            One,

            Two,

            Three

        }

 

        static void Main(string[] args)

        {

            Type enumType = typeof(Test);

 

            //The following prints 3, but we can't use this method in .NET CF

            Console.WriteLine(Enum.GetValues(enumType).Length);

 

            FieldInfo[] infos;

            infos = enumType.GetFields();

 

            //The following prints 4! There is an extra, unrelated Int32 entry named "value__"

            //at the zeroth element of the info array.

            Console.WriteLine(infos.Length);

 

            //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)

            {

                Console.WriteLine(fi.Name);

            }

        }

    }

}

Thursday, 22 March 2007 16:16:48 (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Compact Framework
# Wednesday, 21 February 2007
A while back, I wrote about how to use the Data Access Application Block (DAAB) in the Compact Framework. While this code works just fine, it turns out that Enterprise Library 3.0 will support this natively. I really like the TableExists method that they added, too.

David Hayden wrote a couple of articles about this here and here.

Wednesday, 21 February 2007 23:23:26 (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | ADO.NET | Compact Framework
# Tuesday, 16 January 2007
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:

Tuesday, 16 January 2007 16:45:46 (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Compact Framework
# Tuesday, 12 December 2006
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.

Tuesday, 12 December 2006 14:36:00 (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Compact Framework
# Friday, 08 December 2006
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.

Links:

Friday, 08 December 2006 15:56:00 (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Compact Framework
# Thursday, 07 December 2006
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.

  1. ActiveSync Setup 4.2 - required for several other installs later on.
  2. 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.
  3. 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.
  4. 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
    upgrade patch
    

    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.

  5. 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.
  6. 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.
  7. (Semi-optional) SQL Server 2005 Compact Edition Books Online Community Technology Preview (CTP) - Reference information is always good, right?

Additional notes:

  • 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.

Thursday, 07 December 2006 14:59:00 (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Compact Framework
# Wednesday, 06 December 2006
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.

Wednesday, 06 December 2006 15:50:00 (GMT Standard Time, UTC+00:00)  #    Comments [0] -
ADO.NET | Compact Framework
Navigation
Archive
<2017 August>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2017, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)