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.