iPad Air 2 Clamshell Keyboards

Nearly three years ago I wrote about the Clamcase Pro for iPad 2 which basically turns your iPad 2 into a small laptop. As the iPad 2 became “slower” – meaning that newer version of iOS and various apps were becoming too much for it to handle, I eventually bought an iPad Air 2. My iPad 2 lives on as a remote for Netflix, Plex and YouTube.

Of course my first instinct was to look into buying the iPad Air 2 version of the Clamcase Pro. That turned out to be a problem because I live in Canada. Incipio sell this keyboard through Amazon.ca, but at the time it wasn’t even listed. When it finally did get listed, it was in the neighbourhood of C$350. A far cry for the C$160 or so I had paid for my first keyboard! Hence started the search for another keyboard.

After reading a number of reviews, I decided to go for the ZAGG Slim Book Ultrathin Case. One thing I really liked about it was that the half that holds the iPad is detachable, which made it very easy to remove the iPad to use in portrait mode while still keeping a layer of protection. That is also its weak point: the plastic hinges tend to break after a while. I chose to ignore the reviews on Amazon, especially since some claimed the problem had been fixed. After just a few months, one of the hinges broke. I contacted ZAGG and got a replacement for free (though I had to pay for return shipping to the U.S.) To their credit, it was pretty much a no-questions-asked replacement process and they ship a new keyboard even before you send yours in (you have 60 days to return it, after which time they will charge you the full MSRP). Get the new keyboard and all is good… For about two months. I noticed that the same hinge was beginning to weaken and would more than likely break soon. So much for the problem being fixed. Note that I am very careful with these things, so it’s not the result of abuse or carelessness.

So I decided to look for something else, and that wasn’t easy. I looked again for the iPad Air 2 version of the Clamcase Pro and no luck on the Canadian side – it was still insanely priced. I eventually came across the Cooper Kai Skel (I think that’s the name anyway). This one is closer to the Clamcase Pro in that the half is not detachable like the ZAGG: If you want to use the iPad without the keyboard, you have to take it out of its casing. This one was cheaper than the other two, so I decided to give it a try. It’s not as refined as the other two offerings: The instructions manual is in broken English and the keys took some kind of getting used to (though it didn’t take long to get used to them and not give it a second thought). It works, and includes some copy/paste keys that were available on the Clamcase Pro, but not the ZAGG (did I ever miss those while using the ZAGG…) Also the function for switching keyboards (I type in English and French) actually works on it, unlike the ZAGG which brought me to the iPad Search screen when I used that key…

The ZAGG keyboard had two nice advantages over the other two: The detachable half and a sort of buffer when you started typing while the keyboard had to reconnect. With the other two, you have to start over while the ZAGG keeps the characters in a buffer and sends them to the iPad once the Bluetooth connection has been re-established. Nice! It’s really too bad about the plastic hinges.

In the meantime, the Clamcase Pro for iPad Air 2 has come and gone on Amazon Canada, but is available at a decent price on Amazon USA. Don’t know what’s up with that.

So far the  Cooper Kai Skel has been quite satisfactory. No signs of any parts about to break and the keyboard responds as it should. It’s a good, more affordable alternative. I never got a chance to try the Clamcase Pro for iPad Air 2 , so I don’t know if it’s better or worse than the iPad 2 model.

Lots of fun… 😉

Successful connection to voip.ms using Objective-C

Alright… Been procrastinating again.  But tonight I successfully extracted my Call Detail Records (CDR) from voip.ms using an Objective-C program.  Voip.ms expose a REST/JSON API that makes it possible to do a lot of things, and I’m hoping to create an app to control many features of my account without having to log in to the web site.

The Apple documentation is a bit blurry when you’re just beginning with the Cocoa API, so I had to hunt down a few examples and work from that.  The good news is that nothing did what I wanted, so I had to fiddle quite a bit to get things to work.  Hopefully by the end of the weekend I’ll know what I’m doing well enough that I’ll be able to write a post here about it. Voip.ms provide samples in PHP and .NET, would be nice to have a ready-made Objective-C demo for those who want to get working right away… Stay tuned.  For now, my back needs a break, and I hear Netflix calling…

So long, laptop… Hello iPad and ClamCase Pro

Last year I wrote about converting my HP laptop to Linux Mint, after running Windows Vista and Windows 7 over the years.  A few weeks ago the battery started showing signs of its age.  Since I wasn’t doing anything on the laptop that I can’t do on my iPad, I figured this would be a good time to downsize the gadgetry a little bit.

There was a problem, however: Typing more than a couple of sentences with an onscreen keyboard is a bitch.  Hell, even typing an alphanumeric password is annoying because you have to switch the keyboard mode, often several times (I use weird passwords).

A few months ago, I happened to notice an iPad keyboard, the ClamCase Pro, that looked Clamcase Propretty cool and was getting good reviews.  So I hit the tech web sites again, looking for more recent reviews, and I didn’t see much in terms of negative comments – most of them seemed to be related to a problem located between the keyboard and the chair, while some others were of the “well, duh!” category – such as the keyboard roughly doubling the weight of the iPad. Most of the keyboard’s weight is actually a counterweight so that the iPad won’t tip over when it’s inclined.  Note that I did run into a review where the reviewer mentioned that you cannot use it comfortably on your lap because it will tip over.  I don’t know what that person’s situation was, but I’m typing this with the ClamCase Pro on my lap, with the iPad at a rather steep angle, and it doesn’t even feel like it wants to tip over.

Unlike many keyboards I’ve seen, the ClamCase Pro has a palmrest, which makes it more comfortable for prolonged use.  The keys are very responsive, and I got used to the layout very quickly.  It’s roughly like a standard Mac keyboard, with a few different keys. You can put the iPad in “tablet mode” by folding the keyboard all the way to the back (it’s also recommended to turn off the physical keyboard when you do that, to avoid pressing keys accidentally while holding it).  It does make it kind of heavy to use for reading, however.  Then again, if you’re going to read for a prolonged period, you can always take the iPad out of the enclosure.

After testing this setup for a few days, I determined that this would do just fine as a replacement for my laptop.  Note that I’m not saying that a tablet can replace a laptop (and definitely not a desktop computer): I just wasn’t doing a whole lot with my laptop.  I’d say the only annoyance is that some web sites just don’t work all that great on mobile browsers – yet.

I donated my laptop to a local technology charity named CompuCorps.  I bought the laptop back in 2007 and didn’t expect to get much for it, so I’d rather have it go to someone who needs it.  I’ll get a tax receipt for the donation, so that’s cool. 🙂

So, if you’re looking for a good physical keyboard for your iPad (2, 3, 4), the ClamCase Pro is a solid choice – and as a bonus, it looks pretty slick, not unlike a netbook or Chromebook.  The manufacturer also just released a new version of the keyboard for the thinner iPad Air, which doesn’t seem to be widely available (at the time of writing).

Slowly getting to know Objective-C

So these past few weeks I’ve been toying a little bit with Objective-C and Cocoa using a couple of books from Apress: Learn Objective-C on the Mac: For OS X and iOS and Learn Cocoa on the Mac. Both are very good at introducing the subjects, not going too deep but generally deep enough to get a good understanding of the basics.  I did get tired of toying with the example projects, so after much procrastination, I started doing things on my own.

I figured I’d start by trying to access data stored in the MySQL database I use for my web site,. I’ve been using a crappy MS-Access interface for nearly 12 years and I’d like to retire that thing. So I went out looking for an Objective-C interface to MySQL. No such luck – none is offered by the MySQL group at Oracle. I didn’t find a couple of open source projects meant to fill the gap, but they were pretty old and abandoned. So I set out to do it the hard way: I download the MySQL C API. After all, you can do C in Objective C.

So yeah… My first Objective-C experience (doing a project of my own) is starting as “plain old C”.  I hadn’t done any C in 8 years, and that was for a very small program on Windows.  Things are slowly getting back to me, but want it or not, it does make you appreciate what frameworks such as .NET do for you.  So far I’ve managed to call three stored procedures for adding, updating and retrieving bands from the database.  Which reminds that I need to delete as well. *sigh*  I’m not crazy about stored procedures, but for what I’m setting out to do, it’s going to be easier than writing the SQL directly in the C code – less housekeeping with the strings.

Back to Objective-C – that is some weird-looking language at times, but after and writing some of it, it’s looking less alien.  Even though Apple have added a lot of features over the years, it does show its age here and there – lack of namespaces, the relatively ambiguous status of private methods being two.  But throw in Cocoa and things already get more modern.  That’s a pretty cool framework that I can’t wait to start using for real (once I’m done with the database code). Would be nice if Core Data supported MySQL though. (Hint, hint…)

I also got an idea for an iPad app, but I can’t do everything at once… 🙂

That’s all for now…

Linux Mint for the win…

I guess I got bored with Windows 7 on my 6-year old laptop (né Windows Vista).  Last year I tried to install Ubuntu Linux on it and that was a failure.  Sleep and Hibernate didn’t work (well, waking up was the problem), and on a laptop that’s a no-sale. Linux has a reputation of being a bitch to install on many laptops, and I guess mine was one of those, despite being from a popular line (HP Pavilion dv9000). I didn’t investigate the reason much since I didn’t have much time and just reinstalled Windows 7.  I decided to give it another try this weekend.  That was eventful…

Ubuntu 13.04 was just released a few days ago, so I figured I’d give it another try. I downloaded the 64-bit version.  The installation went relatively well (note: installing Linux is no longer “blazingly fast” compared to Windows, contrary to some claims).  After the installation was completed, the first thing I noticed was: No wireless.  Hmmm… OK.  So let’s try Sleep/Wake up.  Abort! Abort! Abort!  On wake-up, the screen turned to crap and practically everything was unreadable – just like last year.  Fire up the iMac to do some research.  Something about the Nvidia driver.  There’s is an open source version called Nouveau (OK…), which is known to (1) be slow and (2) have problems.  Yet, that is the default version that’s installed. Great.  OK so let’s go to Additional Drivers and select the proprietary Nvidia driver instead (known to (1) be fast and (2) usually work fine.  It let me pick it, but nothing happened.  OK.  Keep reading.  Ah… So 64-bit Linux doesn’t have as many drivers as the 32-bit version.  Well, I don’t really need 64-bit on this laptop anyway, so let’s download the 32-bit version!

Installation was slow again.  But hey, once it was done, I actually could see the various wireless networks available around me (I’m in a condo building, so that means a lengthy list… I wonder if all that stuff is frying my brain… :D)  That’s one down.  Let’s try Sleep/Wake-up again.  No joy.  OK, that driver thing, right… Oops, no love.  More tinkering, no luck.  But… Wait!  I’ve been reading about that other Linux distro, Linux Mint, which apparently sports a better interface.  I did forget to mention that I find Ubuntu’s Unity interface to be somewhat… atrocious.

Soooo… Download Linux Mint (32-bit – no point in screwing around with 64-bit again).  The installation was just as slow as for Ubuntu, which I kind of expected.  And now there it is, the Cinammon interface (they actually have several interfaces available when it’s time to pick a download… I like choice, but man, without trying them all, how the hell am I supposed to know which one I’ll prefer?)  This one is closer to the common Windows interface, and doesn’t have the crappy Unity Launcher (ugh…)

So back to my usual tests:  OK, no wireless again.  Let’s worry about that one later.  Let’s try Sleep/Wake-up.  Oh, screw up (yeah, screwed up again…)  Alright, more reading, but looking for tips specific to Linux Mint.  So I find this guy who says that even when you pick the proprietary Nvidia driver, Nouveau still manages to get in the way (oh, great…) and it doesn’t like to be removed (a driver with feelings?)  BUT, here’s how to “blacklist it” so that the kernel won’t load it.  Well, let’s try that – just a file to edit.  There, done.  Sleep/Wake-up.  Oooooh…  Is this… *click* *click* *click* for a few minutes… Success!  I owe that guy a beer.

OK, time for a more “extreme” test: Hibernate/Wake-up.  Contrary to popular belief, hibernate works fine in Windows (been doing it for years), but is really hit-or-miss with Linux.  Hit the power button… Password screen… So far, so good.  Desktop… Looking good.  *click* *click* frenzy again. Success!

Now where the hell is my wireless crap.  As it turns out, the Broadcom wireless driver is not included with Linux Mint, because apparently Broadcom won’t allow it (yet it was on Ubuntu 32-bit). Anyway, again I found some instructions on setting it up.  Here we go, huge list of nearby wireless networks again.  More success!  This is getting fun.  Time to update my Facebook status, stating that I am tentatively pleased.

I really only use this laptop on weekday mornings for my early browsing/e-mailing/whatever while having a coffee before going to work, so I don’t need a lot on it.  Browser, password manager, text editor.  Firefox is included, but it’s version 16.  Unlike the Windows and Mac versions I’ve been using, this one doesn’t auto-update.  OK.  Wait, what’s this icon in the tray?  A couple of hundred updates are available.  Hmmm.. Let’s not waste time, surely the newest version of Firefox is in there (and yes, it was… but it took a while for all that stuff to download and install – comes with a fresh OS installation…)

Things get complicated when it comes to passwords.  I use KeePass, which is really a .NET program for Windows, but there’s a version that runs under Mono (an open source version of .NET). This version is pretty sucky compared to the original, but it mostly works.  KeePass encrypts the password database, but that’s not enough for me.  I store the password file “in the cloud” so that I can share it between several computers.  I use BoxCryptor for additional encryption.  But wait, there’s no BoxCryptor for Linux.  Just Windows, Mac, iOS and Android.  Oops.  Fear not: the encryption is compatible with encFS.  So from here it was a matter of setting up the cloud service app (thankfully there was one for Linux), encFS, and KeePass.  I found all of these through the Software Sources applications, so at least installation wasn’t painful.  I did find a little application to manage encFS volumes from the tray, so I installed that as well.

Lastly I needed a text editor.  I recently started using Sublime Text on the Mac, and they happen to have Windows and Linux versions.  Installing this one was a bit more involved, since I wanted to install a couple of packages to enhance its functionality. Translation: some shell adventures.  At least Linux, like the Mac but unlike Windows, has an excellent command-line shell.

Sooo… It looks like the laptop is now up and running and ready for the simple tasks I require of it.  Still, Linux requires a bit of tinkering to get where you want, so I’d say it’s not necessarily “ready for grandma”, unlike what many people claim.  Dealing with drivers the way we have to, for very basic functionality, is not something “Joe Average” wants to know about, let alone do.  A lot of people won’t even know what to search for.  But once things are up and running, this is all pretty slick.

Alright, so now I should stop procrastinating (because that’s really what I was doing all that time) and get better acquainted with OS X and iOS programming… Hopefully the topic of a post sometime in the next couple of weeks!

8 months into the Mac world

Well, I had been meaning to post more periodic updates of my journey into the world of Macs, but I didn’t. No good excuse. 😉

It’s been… interesting.  There is quite a bit of getting used to, interface-wise.  OS X has a clean interface, but it is showing its age here and there.  They could borrow a few things from the Windows world.  Just think of having to reach for the mouse when a dialog pops up because there is no keyboard shortcuts on the stupid buttons!  This one is a major pet peeve.  But it hasn’t killed me yet.

As mentioned in my previous post, I decided to get a Mac to explore a new programming platform.  Well, that hasn’t really happened yet.  Or has it?  OK so I haven’t done actual Objective-C programming to create native OS X or iOS applications, but I’ve used a few built-in goodies to automate a lot of tasks on this machine – laborious, repetitive stuff that I had been doing manually for years.  AppleScript, while verbose and a little on the wild side, is great for automatic Mac applications (especially when the applications have explicit support for it).  And since it’s really UNIX running behind the pretty interface, languages like awk as well as UNIX shell scripting are readily available.  I’ve used a mix of some four different languages to automate time-wasting and error-prone manual tasks related to the maintenance of my web site, The Metal Crypt. It took a while to get things the way I wanted, but now the daily update process is almost pain-free.  The next step will be to replace the crappy Microsoft Access interface (for maintaining the site’s MySQL database) I put together in an evening over 10 years ago.  That was a temporary thing until I got around to writing something more permanent.  Ooops…

Did I say Microsoft Access?  Yep.  I’m running a number of Windows applications in a Windows 7 virtual machine using Parallels virtualization software. It does a pretty good job of integrating the two operating systems, especially with a “Coherence mode” that displays Windows applications alongside Mac ones on the OS X desktop.  That works relatively well, though some applications don’t always react so well in that mode.  Other than that I’m running software with a decent Mac equivalent, like Quicken, Catraxx, AssetCat, BookCat, CatVids, Visual Studio, Mp3Tag, MediaMonkey and the Windows Home Server console for managing my WHS-based NAS.  I even went nuts a little bit one day and created an Ubuntu virtual machine, so I was running three operating systems at the same time.  Unfortunately the Linux Coherence mode is not up to par with the Windows one yet, but hopefully Parallels are working on that…

Overall, I’m liking the experience.  The machine and operating system are not as perfect as the Apple zealots scream on every rooftop (I’ve had more OS crashes or hangs than I ever did with Vista and Windows 7 combined over a period of more than 5 years).  But there’s a lot of stuff to like, and it’s fun overall.  Did I mention monitor quality?  The iMac’s built-in 27″ monitor is excellent, and so is the additional 27″ Thunderbolt display.  I’ve got quite a bit of stuff available simultaneously on all that screen real estate.  Maybe too much, now than I think about it…

Now, with an unexpected move last fall and then a lot of overtime last winter, as mentioned earlier I never got around to doing some “real” programming on this puppy.  I just added a few Xcode components to get ready to roll, and spent some time swearing because the damn thing has somewhat weird support for source control (actually, I’m still swearing since I have yet to get it to play with Subversion).  Little things.  Now it’s time to dig deeper in Josh Smith‘s book iOS Programming for .NET Developers.  After all, that’s what kind of triggered this Mac adventure in the first place…

Flirting With the Other Side…

A couple of weeks ago I got a crazy idea: Buying a Mac.  Well, the idea started with an interest in learning another platform and also taking a shot at iOS development.  I had been juggling with the idea for a while, and the last straw was when Josh Smith released his new book iOS Programming for .NET Developers. More on that once I’ve actually read it (I’ve only read the sample so far).

So this past week the iMac got here and I installed it last night. Talk about foreign land. Still getting a hang of all the differences (lots of keyboard keys react differently from Windows, for example) and of course the way you interact with OS X is at times very much different from how we do things in Windows. After upgrading to the new OS X “Mountain Lion”, I am now installing various applications and configuring the OS, slowly but surely. Last night and this morning I was freaking out, but I’m slowly getting used to it. Oh and that 27″ monitor looks like it wants to swallow me whole… Bottom line, this is a very nice and elegant machine, and having had to unplug the PC tower to move it elsewhere, I certainly appreciate how little cabling is necessary – an all-in-one computer does have its advantages.

The iMac is really a fancy PC, so once I got the basics up and running I’ll be installing Windows 7 on it as well.

More later…

Moving to VoIP with voip.ms

So a few weeks ago Rogers sent a letter saying that my Internet and Home Phone services were going up $2 per month beginning in March.  Not a huge increase, but then it made me realize I’d be paying nearly $50 a month for my landline, which I don’t use all that much (and I use the prepaid cellphone even less).  I looked into possibly replacing both the landline and the prepaid cellphone by a smartphone with some “decent” plan (and coverage, for when I visit family), but no one company had anything that really satisfied me (Koodo Mobile was the closest).  That was still a rather expensive proposition for something I knew I wouldn’t use all that much (and I’m not interested in becoming one of those cyberzombies that walk around head down, their eyes glued to their smartphone).

I decided to take a second look at VoIP.  That’s a technology I’ve been staying away from because I wasn’t too keen on relying on the Internet connection being up all the time. But then again, in nearly six years I don’t think my connection has been down six hours – not while I was at home anyway.  Also my nephew has a MagicJack, which is probably as simple as it gets as far as VoIP goes – just plug it into a computer’s USB port.  I don’t like the sound quality when I talk to him over that line, but reading various comments on VoIP forums, it seems like it could be an issue with his Internet connection – he does live in a “rural” area and maybe that connection just doesn’t have the speed that we get in the city.

So I started doing some extensive research on the various services.  A lot of the big ones such as Vonage and Primus charge quite a bit for VoIP – say around $30/month (this varies).  Some lesser-known services could be as low as $9.95 assuming you pay for a year in advance, but the reviews weren’t so great.  That’s when I started running into “pay-as-you-go” VoIP providers and realized this was probably the best alternative for a light phone user like me.

I ended up choosing voip.ms, a company based in Montreal and has been around for almost four years (which is rather long in the VoIP world). Some of the reasons for choosing them were that they were one of very few VoIP providers that had overwhelmingly positive reviews over at DSLReports.com, that they are based in Canada (though they charge in U.S. dollars, like most of the smaller guys), the feature set is also quite extensive – way too much to discuss here. This is also a “Bring Your Own Device” provider in that you don’t/can’t buy the hardware from them (unlike guys like Vonage and MagicJack, etc who force you to use their locked-in hardware), so I was free to buy the VoIP ATA of my choosing. And of course the prices are pretty good: $0.99/month for the phone number, $1.50/month for e911, and then after that it’s only the minutes I use. Depending on various factors (incoming, outgoing, value vs. premium routing), the price goes from about half a cent per minute to a little over a cent. Assuming you have to pay about a cent a minute, that’s roughly $10 for 1000 minutes. I normally don’t go anywhere near that. So I estimate that my monthly cost will go down to anywhere between $4 and $6, depending on how chatty I get on a given month. 😉

I first signed up on the service – for free – and ran an echo test using a softphone. The quality was crystal clear. The next day I went out and bought a Cisco Linksys PAP2T-NA ATA. 45 minutes later I was making my first phone call, and that includes upgrading the firmware, fishing for that extra phone I knew I had somewhere, and adding funds to my voip.ms account.

A week later, after testing it for a few days, I requested a port of my existing phone number. This took a week (normal delay – this can take up to four weeks if whatever company currently “owns” your phone number decides to take its time). The day of the port the phone was down for a few hours while it was being transferred between providers. Later in the day I cancelled my Home Phone with Rogers (thank you Rogers for not annoying me with the “30 day service cancellation notice”), which brought my monthly Rogers bill down by nearly half. That’s a significant amount of cash.

voip.ms is a more “techie-oriented” provider (at the moment anyway – they’re working on making things more user-friendly) than guys like Vonage or Primus, though quite frankly, with the PAP2T setup instructions on their wiki, all I had to do was follow the instructions to the letter and everything worked right away. So even though I found all the terminology and options intimidating at first, I could almost have done set this up with my eyes closed.

Obviously I can’t guarantee – and I am not saying – that voip.ms is the best VoIP provider out there. I haven’t had any experience with the other providers. But between the ease of getting things running and not having to wait for some hardware in the mail, the pricing and features, this is an excellent deal. I’ve had to contact their support a few times, not for problems but for questions and clarifications, and I always got a reply back very quickly even when I set the ticket priority to “Low”. I even got a few replies after their official technical support hours on a Saturday. And of course so far the call quality has been excellent; the persons I talked to said it sounded the same or even better than my landline. So now I can save money to cover for whatever else will be going up in price. 🙂

Visualizing GUIDs in the Visual Studio 2008 debugger

The application I’m currently developing at work makes extensive use of GUIDs.  If you’ve debugged Visual BASIC code in Visual Studio, you’ve probably noticed that it doesn’t display GUID values when watching a variables:

VS 2008 Watch Window showing a GUID as empty

Not very useful, is it?  I’ve heard that GUIDs display fine when debugging C#, but I haven’t tried (I’m lazy.)

A few weeks ago I ran into a blog that explained how to write a very basic visualizer to address this problem. Unfortunately I didn’t keep the link and have yet to remember the search text I used to get there – so somewhere somebody is not getting due credit for this post.  I’m pretty sure it was on a Microsoft blog.  Either way, I’ll update this post if I ever find it again – for now, let it just be known that I did not come up with this technique by myself. 😉

Writing the Visualizer

  1. To create the visualizer, create a new Visual BASIC Class Library and call it “GuidVisualizer” (or whatever name you prefer.)
  2. Replace the generated class declaration with this code:
    <Assembly: DebuggerDisplay("{ToString}", Target:=GetType(Guid))>
    Public Class GuidVisualizer
    End Class
  3. Compile the library

Copy and try the Visualizer DLL

  1. Copy the generated DLL to My Documents\Visual Studio 2008\Visualizers
  2. Start Visual Studio 2008.  Using the sample example as above, the GUID is now displayedGUID displayed correctly in the VS 2008 watch window

The watch window still obsesses on the “empty” if you keep expanding the value, but at least now you can see the real value.

GUIDs in Oracle

We’re starting a new project at work and we’ve decided to use GUIDs as unique identifiers in the tables.  Now, if your database server is SQL Server, this is no big deal: You simply choose the uniqueidentifier column type and you’re in business.  You can read and write that from .NET, use it in ad hoc SELECT statements, etc…

Oracle GUIDs don’t have much to do with the ones from Microsoft software, so let’s not go there.  I started looking for a solution on the Internet and boy, did I see just about every possible solution out there, including storing it as a 37 character string.  Call me crazy, but I wasn’t about to use this as a primary key.

Eventually I found a short post in a lengthy discussion, almost missed it actually, and the solution couldn’t have been simpler.  So here it is.  In this article I’ll explain how to use .NET GUIDs with Oracle, with a few short code samples.  Hopefully it’ll result in some people not wasting as much time on this as I did.

Oracle Data Type for GUIDs

There is no GUID or uniqueidentifier type in Oracle, so what do you use to store a .NET GUID? (If you don’t want to store it as a string, that is.)  A .NET GUID can be passed to Oracle as a 16-byte byte array, so the most efficient (at least I think so) data type is RAW(16).

Writing and reading GUIDs from .NET

You’ll have to convert your .NET GUID to pass it to Oracle.  This is simple, since the GUID class has a ToByteArray method.  This is some Visual BASIC sample code that creates a new GUID and puts it in an outbound parameter – in this example I use the syntax from the Oracle .NET Data Provider, but I’ve also done this using the Microsoft .NET Provider for Oracle, the Microsoft ODBC driver for Oracle, and Oracle’s own ODBC provider.

‘ Create a new GUID
Dim newguid As Guid = Guid.NewGuid

‘ Parameter settings
Dim empid As OracleParameter = _
cmd.Parameters.Add (“in_empid”, OracleDbType.Raw)
empid.Direction = ParameterDirection.Input
empid.Value = newguid.ToByteArray

Pretty simple, isn’t it?  Of course, if you look at the result in the Oracle table, it won’t look like a GUID, but just a string of bytes – the content of the byte array. You can SELECT on that value by enclosing the content of the RAW(16) field in single quotes (a string), and using the HEXTORAW() function.  That’s almost as good as selecting a GUID in SQL Server. 🙂

Reading the GUID back into .NET is quite straightforward as well.  In the code below, dr is a DataReader, and the GUID is the first value returned in the row (hence the reference to the 0 index in GetOracleBinary).  The code displays the GUID on the console:

Console.WriteLine(“GUID read from Oracle table: ” & _
New Guid(CType(dr.GetOracleBinary(0), _

A little bit cramped, but here’s what’s going on:

  1. We get the content of the RAW(16) field using GetOracleBinary
  2. We cast the value to a Byte array
  3. We create a new GUID object from that Byte array

That’s all there is to it!