Arcane Thoughts: Tidbits from the web

I’m headed out on a road trip, so this will most likely be the only post this week. Just wanted to hit a few interesting tidbits I’ve found on the web this week.

If you haven’t been keeping up with .Net Rocks lately, you should (see the Arcane Links page). The last few shows have been some really good interviews with lots of super geeky, in depth technical content. The Kate Gregory show was really great (“It’s the speed of light. We’re screwed.”) The MLB show was really good on WCF and card space.

Want to see something disturbing? Thanks to Carl Franklin, I may never look at another chicken mcnugget again.

There’s an interesting list of top 10 lists on Coding Horror.

One of my posts got quoted on the CBS blog report.

And finally, someone I know just started her blog, go check it out:

Have a good week!


SSIS and the Metadata Out of Sync Error

Worked late tonight on a problem we’ve been having with our SSIS (SQL Server Integration Services) package. It would run, but give us a weird error about the metadata being out of sync.

It turned out to be a self inflicted error. In the SQL that drove this particular package, the statement ended with …table1.field3, nvl(table2.field4, ‘Missing’) from table1…. Turns out SSIS didn’t like the nvl part. (nvl by the way is an Oracle statement that equates to if field4 is null, return ‘Missing’, otherwise return field4.) Oh, it understood the nvl command OK, but it didn’t like the fact we failed to alias the command in the SQL.

When I updated the SQL to read nvl(table2.field4, ‘Missing’) as field4 from…, AND I did a build on the package, SSIS was happy. Note though that it kept reporting the problem until I did another build on the package, it drove me nuts for a bit until I thought to rebuild the thing.

To sum it up, never leave just an expression in your SQL, always alias it or you too could fall victim to the mysterious Metadata out of Sync Error.

Arcane Thoughts: Has Microsoft become Big Blue?

Back in the early 80’s when Microsoft first came on the marketplace, it was IBM who dominated. They had the OS, they had the computers. While they dominated the business environment, they weren’t seen as very responsive to the home consumer. (Anyone remember the IBM PCjr?)

Enter Microsoft, who came out with slick applications designed for “the little guy”. They were quick to market, had cool offerings that worked, and were reasonably priced. Oh how times have changed.

Much like IBM in the 80’s, today Microsoft is a dominate player in the enterprise marketplace. They own the desktop market, have a enterprise ready database in SQL Server 2005, their Great Plains accounting and CRM software are major players in their fields. And don’t get me started on their awesome development tools.

But when it comes to the home market they seem to keep missing the boat, with I admit the notable exception of the XBox. For example, their One Care virus software failed miserable in head to head tests with other antivirus software (,129722-page,1-c,viruses/article.html). And while they claim high numbers, I hear little in the blogosphere about the new Windows Live website. And then there’s Zune.

Clearly Microsoft needs a change. Either change the model, as IBM did to focus on the business areas they are so good at, or get some new leadership to recapture the lead in the consumer arena.

But hey, that’s just my Arcane thinking, I could be wrong. Leave your opinion…

Encoding Strings to Base64 in C#

I recently had the need to convert simple strings back and forth from Base64 encoding. It turned out to be relatively simple in .Net, once you figured out which class libraries you needed to combine.

It turns out the System.Convert has two handy methods for dealing with Base64, ToBase64String and FromBase64String. On the ToBase64String, we have a bit of a challenge, since it expects a byte array and not a string to be passed in.

It does make a certain amount of sense, typically you aren’t encoding a simple string but instead a binary object such as a file, which is usually represented as an array of bytes. For us, this means we have to take our string and convert it to a byte array.

You’d think the string class would have a nice static method to handle this, but alas it does not. Instead we have to turn to System.Text. I imagine most of you are working with ASCII encoding, so here we’ll call on the ASCIIEncoding.ASCIII class, and use it’s GetBytes to convert a string to bytes.

The small method below combines the two methods I’ve described to create a Base64 encoded string from a normal string.

    static public string EncodeTo64(string toEncode)


      byte[] toEncodeAsBytes

            = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);

      string returnValue

            = System.Convert.ToBase64String(toEncodeAsBytes);

      return returnValue;



Note two things, first I am using ASCII encoding, which should cover most folks. Just in case though, System.Text has encodings for the various flavors of UTF as well as Unicode. Just choose the appropriate encoding method for your need.

Second, I made the class static because I was using a console app for my test harness. While it could be static in your class, there’s no reason it has to be. Your choice.

OK, we’ve got the string encoded, at some point we’re going to want to decode it. We essentially do the reverse of encoding, we call the FromBase64String and pass in our encoded string, which returns a byte array. We then call the AsciiEncoding GetString to convert our byte array to a string. Here’s a small method to Decode your Base64 strings.

    static public string DecodeFrom64(string encodedData)


      byte[] encodedDataAsBytes

          = System.Convert.FromBase64String(encodedData);

      string returnValue =


      return returnValue;



Finally, here’s a simple test harness, done in a console app, to show you calls to the two methods.


      string myData = “Here is a string to encode.”;


      string myDataEncoded = EncodeTo64(myData);



      string myDataUnencoded = DecodeFrom64(myDataEncoded);





Be aware, I’ve done no error checking here. My little methods assume that the data you are decoding will properly convert to and from a string. If that’s not the case you could wind up with a serious case of gibberish, if not cause a run time exception. If you are not positive that all you are dealing with is simple strings, then make effort to include some try / catch logic in your implementation.

Arcane Education: Alabama Code Camp IV

Yes, it’s spring time, when the flowers are in bloom, and a young man’s fancy turns to… .NET!

Alabama Code Camp IV is coming up quick, April 14th is just a few short weeks away. For those in the south-east, this one will be held in Mobile AL. See all the details at:

If this is anything like the previous ones it’ll be great, tons of great speakers and lots of good swag. If you have never been to Mobile before, there’s a lot to see and do. My family is coming along and we’re going to make a weekend of it.

Top on my list (after code camp of course) is seeing the USS Alabama (, a WW II Battleship. At the same location they have the USS Drum, a submarine, a B52, an A-12 Blackbird, and tons of other exhibits.

If battleships aren’t your thing, Mobile is loaded with opportunities, check out Yahoo’s top 16 list at,  or the Mobile city guide on (

And for the beach goers, Orange Beach is right next door to Mobile (literally). Check out the fun in the Gulf of Mexico at

So there you go, a whole day of geeky fun for you, and plenty of ways for the family to be out spending your money, oops I mean having fun while you are getting an education. Well, at least Code Camp is free!

So quit sitting on your duff and start making plans today!

Arcane Thoughts: Ze Frank’s Web

Ze Frank has had me thinking about the role of creativity on the web. A lot. There’s a great deal of talk about Web 1.0 versus Web 2.0. Certainly there are some compelling new technologies that some might consider falling into the 2.0 field, such as AJAX.

I don’t think Web 2.0 can be defined by technology though. I think it’s more about the way people use the web. Web 1.0 became strongly driven by business. Sure, individuals had pages, but it was business who dominated Web 1.0.

With 2.0, it seems the individual has moved to the forefront. Blogs, podcasts, videocasts, twitter, all examples of the individual extending his or her creativity to the web. Not only does it give a place to host, but to communicate. An artist can get immediate feedback and interaction with their audience. A global, world wide audience.

In the interest of extending my own creative streak, I’m branching out, trying some of the new services. I’ve setup new twitter and tumblog accounts. Twitter, well I’m not sure why, to be honest I’m not 100% sold on the usefulness, but what the heck.

My tumblog will host my pictures. I’ve had a long interest in digital photography, and I’ll put some of my favorites here for you to enjoy.

Don’t worry, I’ll still be posting .Net magic here, but everyone has to find ways to be awesome. How about you?

So long Ze… You’ll be missed.

About six months ago I discovered The Show, with Ze Frank ( Each day Ze Frank puts on a video podcast that is humorous, entertaining, enraging, thought provoking, but above all, inspirational.

The running theme of the show, started one year ago today, was that Ze wanted to join something called “The League of Awesomeness”, a society out to make the world a more awesome place. His initiation into the league was to do a video podcast for one year, hence The Show.

The real point though, was not simply to do a video each day, but to engage in a conversation with the viewers, and to inspire them to debate, discuss, and create. The forums are populated with his fans, known as “sports racers”. Fans contribute greetings, graphics, songs, and more to make the show a true collaboration, with Ze at the helm.

Today, March 16, 2007 is the last episode of The Show. It comes to an end as Ze Frank fulfills his internship to the league. The real gift Ze has given over the last year is not videos, but inspiration. Through his encouragement to “be awesome” he has inspired countless sports racers to create their own content and share it with the web.

Now that Ze Frank has graduated to full league membership, I am hopeful the gift he gave, that of encouraging people to create and contribute, continues. I challenge everyone, go out and create something. Videos, songs, poetry, art, even a simple blog like this one, go create and share with the rest of the world. Unleash your potential to be awesome.

So long Ze, and welcome to the League of Awesomeness.

It couldn’t be more deserved.

Arcane Tricks: Cut / Copy / Paste To and From Virtual PC

As you might guess from my various posts, I like using Virtual PC. It has one annoyance, you can’t cut / copy / paste between the Virtual PC and another machine, like the host operating system.

This is actually a good thing, as it’s a security feature. It allows you to test suspicious software safely, without fear of it damaging your host. There are times though, when you know it is safe to allow the cut / copy / paste connection between your Virtual PC and your host. It would be nice to have a switch or option that turns this on and off. Sadly, it’s not there.

There is a work around though. Back in December, I talked about the combination of Virtual PC and Remote Desktop. ( or . While VPC lacks the ability to cut / copy / paste, Remote Desktop does not. Using Remote Desktop you can cut, copy, and paste data from your host (or any other remotely controlled PC) to the Virtual PC you are controlling via Remote Desktop.

All you have to do is follow the instructions in the post mentioned above, and “remote” into the virtual machine. Yes, you will be remoting to a machine running on the same box, but all the remote desktop software sees is an IP address. It can’t tell if that IP is on the same host computer or one across the planet.

This little trick has saved me several times, and was one of those “doh!” moments when it first occurred to me. Even if you have been following along and using Remote Desktop with VPC, it may not have occurred to you to use it on the same machine.


Arcane Thoughts: Thanks to you, ArcaneCode made the top 5!

Thanks! Thanks to all of you. In the WordPress Wednesday they were showing how rapidly the list of top blogs changes. For a brief time anyway, the Ubuntu post was #5 on the “What’s Hot” list. Read for yourself at or

ArcaneCode has been averaging about 800 hits a day lately, and has had over 24,000 hits at the time I write this.

I just wanted to say thanks to everyone who has read ArcaneCode, and passed on links to all their friends. That’s what the whole social web thing is all about, helping each other out.


Allowing Remote Desktop Access to Windows XP, Step by Step

Way back in October of last year ( or I wrote about using the Remote Desktop tool.

A few people have had problems accessing their desktops, so I thought I’d provide some step by step instructions on how to allow your computer to be access via Remote Desktop.

First, open Control Panel.Then, open the User Accounts.

Click “Change the way users log on or off” and uncheck “Use the Welcome screen”. Click Apply Options.

[Picture of User Acct Screen]

Click on your account, and make sure it has a password. If not, click “Create a password”, then create one.

Close out the user accounts, then close out Control Panel.

Right click on the “My Computer” icon, and pick Properties.

Select the “Remote” tab.

Check the box on that reads “Allow users to connect remotely to this computer”.

[Pic of System Properties Remote tab]

Click Apply and OK, and you should now be able to access your computer via Remote Desktop. Just follow my instructions in the post I mentioned at the beginning of the message and you should be in good shape!

Developing From The Network

When developing, it’s nice to be able to save and run your projects from your corporate network. Network drives are typically backed up, where local hard drives are often not unless you take the time to do it yourself.

As part of it’s code security initiative, the .Net Framework protects us by not allowing us to run code from an “unsafe” location. Unfortunately .Net often sees company networks as locations that are not safe.

It’s easy enough to remedy, with a simple command that no one seems to know about. I finally lucked out and found a brief reference on Chris Sells blog. I’d like to expound on his entry slightly and go into a little detail about what’s going on.

First though, let me give you the command in case you are the type of person who just wants a quick fix:

First, navigate to your c:\windows\\framework\ directory. Now, if you are using .Net 1.1, drop into the v1.1.4322 folder, if you are using .Net 2.0, go into the v2.0.50727 directory. Now execute the command

caspol -q -machine -addgroup 1 -url file://z:/* FullTrust -name “Z Drive”

Make sure to type it in all as one single command, in case your reader has wrapped the line. The two things you need to note are the folder designation, z:/* and the name in quotes “Z Drive”. For the z:/* put the drive letter for the network drive you want to give permissions to. You can also add a folder if you want to narrow it down for security, such as z:/myprojects/* .

Inside the quotes you can put anything you want, I made it easy and named it Z Drive, but you could call it “Projects on Z” or “My Projects” or “Arcane is a wizard at this coding stuff”.

Now for those who are a bit more inquisitive, here’s a breakdown of the command line options.

-q     Runs in quiet mode, suppressing all of the normal “are you sure” prompts

-machine     The commands will apply to this computer.

-addgroup     This adds a new security group to your machine, with the name you enter in quotes.

1     is the parent group under which you are adding, use 1 for the base group on the machine.

-url file:     Indicates we are adding a url, in the form of a file spec. Normally caspol expects your adding a website or webservice you want to execute code from, using the file: spec gives us a work around to add a network drive.

FullTrust     Again, an obvious entry that sets the security level in addgroup.

-name     Obviously the name you want to give to your group. Following the –name place the name in double quotes, such as –name “Z Drive”

After issuing the command, you probably want to verify your new permissions have been set. To do so, use this command:

caspol –listgroups

This will list your security groups, with your newly named group (the name you put in quotes) at the bottom of the list. It should look something like:

1.7. Url – file://z:/*: FullTrust

Finally, if you want to find out more about the access security policy tool, use the command

caspol -?

To display screen after screen of help text.

And that’s how you can set it up so you can run your .Net applications from your company network.

Dictionaries in C#: OrderedDictionary

There are times in life when you’d like to have your cake and eat it too. With a hashtable, this means there are times when you want to use the keys to look things up, or iterate in a foreach using DictionaryEntry objects. There are other times though when it would be easiest to treat the collection as if it were an array, using a traditional for(int i=0; … type syntax.

The OrderedDictionary is what lets you have the best of both worlds. Using it, you can perform specific actions at a numeric index in the collection, or you can use the Dictionary Entry style of looping over the collection. Like the other specialized dictionaries I’ve mentioned in the latter part of this week, you will need a using System.Collections.Specialized reference.

Let’s take a look at an example.

      OrderedDictionary myOD = new OrderedDictionary();


      myOD.Add(“01”, “First”);

      myOD.Add(“02”, “Second”);

      myOD.Add(“03”, “Third”);

      myOD.Add(“04”, “Fourth”);

      myOD.Add(“05”, “Fifth”);


      // Reference the values array style

      for (int i = 0; i < myOD.Count; i++)


        // Create a strongly typed variable to hold the

        // generic object in myOD[], then do a cast

        string valueString = (string) myOD[i];




      // Reference the values Dictionary style

      foreach(DictionaryEntry myDE in myOD)





Above you can see I used two different methods to iterate over my collection. In the first example, I used a for loop and a numeric index to retrieve each object (in this case a string) stored in the collection. Using a cast I convert it from the generic object type into a more strongly typed variable.

While it’s true I simply could have used Console.WriteLine(myOD[i].ToString()), you will not always be dealing with string data in your value. This example demonstrates how to do a simple conversion.

In the second loop, you can see code similar to what has been shown all week, using a DictionaryEntry object to iterate over the collection.

The other advantage to an OrderedDictionary is speed. When going over a large collection, reading the OrderedDictionary using the first example, the numeric index, is always going to be faster than using the dictionary style method.

When you need both the power of a collection, and the simple access of a numeric index, the OrderedDictionary is the collection of choice.

Arcane Thoughts: Hug Your Developer Evangelist Today

Last night Doug Turnure came to give a presentation to the Birmingham Software Developers Association (BSDA). Doug is the Microsoft Developer’s Evangelist for Alabama / Georgia / Mississippi. Brian Hitney, Developer Evangelist for North and South Carolina happened to be in Atlanta where Doug lives, and came along.

Together, the pair did an excellent presentation on Vista. Doug started things out with the new gadget sidebar component, the various kinds of gadgets, and gave a demonstration on developing a gadget.

Brian then picked up the presentation, giving us a technical overview of the core changes to the OS. He covered a surprising amount of technical detail in the short amount of time he had, and made it understandable.

We had a packed room, but Doug and Brian stayed until they’d answered every question from the crowd. They did a great job, and I just wanted to take a moment to thank them publicly. The Developer Evangelists do a lot for us, they spend a lot of time away from home visiting user groups and giving us a lot of free training and advice.

Take time to get to know your developer evangelist, work with them to coordinate presentations at your user groups. And don’t forget to thank them when it’s all over. Thanks guys!

Dictionaries in C#: The SortedList

There are times when you need to sort your collection easily. Fortunately, there is a special dictionary called the SortedList to handle these needs. The SortedList is part of the System.Collections.Specialized library (don’t forget your using reference!).

There is one thing to understand that is a bit counter intuitive. The SortedList sorts off of the Key, and not the Value. While this may not seem natural, it can work to your advantage in times when users want to have peculiar sort orders. You can store the odd sort in the key, then display the values to the users.

In my simple example below, I’ve created a SortedList of the artists I might listen to during a day of programming. To make the sort case insensitive, I entered all the keys in lower case, then the value is the artist name in normal type.

      SortedList myMusic = new SortedList();


      myMusic.Add(“zztop”, “ZZTop”);

      myMusic.Add(“midnight synidicate”, “Midnight Syndicate”);

      myMusic.Add(“kate bush”, “Kate Bush”);

      myMusic.Add(“bond”, “Bond”);

      myMusic.Add(“clint black”, “Clint Black”);

      myMusic.Add(“queen latifah”, “Queen Latifah”);


      foreach (DictionaryEntry favoriteArtist in myMusic)





Produces this output in the command window:

Clint Black
Kate Bush
Midnight Syndicate
Queen Latifah

When you need to maintain a frequently changing list of values that need to be sorted, using the SortedList dictionary can be a real time saver.

Dictionaries in C#: The HybridDictionary

So far we’ve looked at the HashTable collection, and determined that it’s the way to go for large collections. We’ve also taken a look at the ListDictionary, which is geared towards very small collections. But what if you don’t know how big your collection will be?

There are many situations where at design time you simply can not know what the final size of your collection will be. Sometimes it will depend on user input, what range of data the user selects for example. Other times it may be dependant on the data, how much is out there for you to use. There’s enough uncertainty in all our lives to get stressed out, so to keep us calm Microsoft has provided the HybridDictionary collection.

A HybridDictionary will self monitor itself. Initially, and while it remains small the HybridDictionary will internally keep itself as a ListDictionary. Once it exceeds a certain threshold, it will then convert it’s data into a HashTable. The nice part is you don’t have to care when, or what state it is currently in. All you have to know is the HybridDictionary is managing the memory most efficiently on your behalf.

Like it’s sibling the ListDictionary, the HybridDictionary will require a using System.Collections.Specialized reference. After that, it has the same interface as the HashTable and can be treated as such.

      HybridDictionary genders = new HybridDictionary();


      genders.Add(“M”, “Male”);

      genders.Add(“F”, “Female”);


The question many will ask “well why not just use a HybridDictionary all the time?” As with most things in life, there is a trade off. There is a some overhead associated with HybridDictionaries, as they have to constantly monitor their own size, then convert back and forth between ListDictionaries and HashTables as needed. In return, you get the best possible performance from your collection as it changes in size.

The moral of the story, when you know you have a small collection, use a ListDictionary. On the other hand, if you know with certainty your collection will be large, use a HashTable. But for all those other times when you just don’t know, the HybridDictionary is your answer.