Saturday, July 17, 2004

A Test for GUIDs

MCMS tags each object with a GUID and one of the most efficient ways of retrieving them from the repository is to use the Searches.GetByGuid() method. Simply pass in valid GUID string and you get the requested HierarchyItem.
Well, that works, *if* you have the correct GUID. When you pass in a badly form GUID, say when forgetting the opening { and closing } braces, or miss out any of its hyphens, it coughs up this rather obscure message "Server ODBC error. Please contact Administrator". This same message appears on several other kinds of errors but most of the time, the cause is a bad GUID input parameter.
To get around this, here's an IsGuid() method that returns a boolean indicating whether the input string parameter is a valid string: 
private static bool IsGuid(string guid)
      Guid testGuid = new Guid(guid);
      return (false);

Before calling the Searches.GetByGuid() method, test the GUID to see if its valid whenever you are not sure. It could save you some hours of troubleshooting :-)


Post a Comment

<< Home