Xerratus
Happily stressed out, since 1974


 
Wednesday, March 22, 2006
<< Paris Honeymoon Lost
Annoying Invalid access to memory location exception solution >>

Thank you!  Thank you to the person who completely circumvented a built in .NET function for creating new Guids.  This was so bad and frickin unbelievable that I actually stopped my work to post this because of my complete disbelief. 

First off, here is the CORRECT way to create a new Guid:

   1:  // Uses the built in function to return a guid
   2:  private Guid _globalId = Guid.NewGuid();

That's it!  Easy, right?  Uses built in functionality.

But here is the ingenious way I found this morning that completely wowed me:

   1:  // Goes to the database, uses select newid() from a sproc to return a new guid
   2:  private Guid _globalId = LicenseVerification.ClientAccessLicenseBusiness.CreateGuid();

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:   
   5:  namespace LicenseVerification
   6:  {
   7:      public class ClientAccessLicenseBusiness
   8:      {
   9:          //...snip...
  10:   
  11:          public static Guid CreateGuid()
  12:          {
  13:              return LicenseData.CreateGuid();
  14:          }
  15:   
  16:          //...snip...
  17:      }
  18:   
  19:      public class LicenseData
  20:      {
  21:          //...snip...
  22:   
  23:          public static Guid CreateGuid()
  24:          {
  25:              Guid newGuid = (Guid)SQLHelper.ExecuteScalar(DataConfig.ConnectionString, CommandType.StoredProcedure, "ClientAccessList_CreateGuid");
  26:              return newGuid;
  27:          }
  28:   
  29:          //...snip...
  30:      }
  31:  }

   1:  CREATE PROC [dbo].[ClientAccessList_CreateGuid]
   2:  AS
   3:  select newid() 

Yes, you are seeing this correctly!  The programmer who wrote this thought that going thru the business & data layer to call a stored procedure would be the best way to create a new Guid.  I'm in complete shock. 

Monday, April 28, 2008 5:34:12 PM (Pacific Standard Time, UTC-08:00)
I can think of a number of reasons why this was done.

The are more than one algorithm for generating a Guid, the algorithm used by .NET may not be the same as the algorithm used by the DB. Now, if there are more than one sources for creating data in the DB then you need to ensure that each of these sources use the same algorithm or you may get collisions (duplicate Guids) from the different sources.

Just a thought.
random guy
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview