When is a UUID not a UUID? When it automagically changes case on you.
Mike Amundsen came to me with a minor gripe about being inconsistent with casing GUIDs coming from the database. He was getting lower case in the detail and upper case in the list. I didn't think I was doing that so I did a little bit of research. Microsoft, as can be the case when you're a very large company, is a bit inconsistent. According to the proposed standard (RFC-4122):
Each field is treated as an integer and has its value printed as a zero-filled hexadecimal digit string with the most significant digit first. The hexadecimal values "a" through "f" are output as lower case characters and are case insensitive on input.
And .NET does this correctly. Put the following code into a console app.
C#
string stringControlGUID = "4A71C777-1F6E-45D5-89D5-88CCE2AAD25B";
Guid guidControlGUID = new Guid(stringControlGUID);
string stringTestGUID = guidControlGUID.ToString();
if(stringControlGUID != stringTestGUID )
Console.WriteLine("You can see that {0} != {1}", stringControlGUID, stringTestGUID);
else
Console.WriteLine("You can see that {0} == {1}", stringControlGUID, stringTestGUID);
Console.ReadKey();
VB
Dim stringControlGUID As String = "4A71C777-1F6E-45D5-89D5-88CCE2AAD25B"
Dim guidControlGUID As Guid = New Guid(stringControlGUID)
Dim stringTestGUID As String = guidControlGUID.ToString()
If stringControlGUID = stringTestGUID Then
Console.WriteLine("You can see that {0} != {1}", stringControlGUID, stringTestGUID)
Else
Console.WriteLine("You can see that {0} == {1}", stringControlGUID, stringTestGUID)
End If
Console.ReadKey()
End Sub
The C# version will say the value are not equal because capitalization figures into its equation. The VB code will show both the upper and lower case versions of the string but it ignores capitalization.
So, for future reference, I'm going to make any UUIDs I add to the database CHAR(36) and lower case them before I add them. Because SQL Server believes all UUIDs should be upper case:
SELECT CONVERT(uniqueidentifier, LOWER('4A71C777-1F6E-45D5-89D5-88CCE2AAD25B'))