Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. GUID Unique identifer theory question

GUID Unique identifer theory question

Scheduled Pinned Locked Moved C#
questionsysadminxmltutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saludalabs
    wrote on last edited by
    #1

    I have a question about GUID. I created a calender admin program that stores event data in an xml file. The xml file consist of an element called call ID. I am using ID as a key. Each event has a unique id. My code generates a GUID for each new event. Currently I set up a method in my code behind to see if the GUID exist before I except the value of the new GUID. My understanding the sytem should generate a unique GUID each time you create one. I am thinking it is possible to get a duplicate GUID value, for example if I move the application to a new server. Is this good practice or just a waste of resources? Thanks, David

    P L 2 Replies Last reply
    0
    • S saludalabs

      I have a question about GUID. I created a calender admin program that stores event data in an xml file. The xml file consist of an element called call ID. I am using ID as a key. Each event has a unique id. My code generates a GUID for each new event. Currently I set up a method in my code behind to see if the GUID exist before I except the value of the new GUID. My understanding the sytem should generate a unique GUID each time you create one. I am thinking it is possible to get a duplicate GUID value, for example if I move the application to a new server. Is this good practice or just a waste of resources? Thanks, David

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Better safe than sorry. I generally use a database, so the GUIDs I generate as primary keys gets checked by the database engine. But, yes, they do get checked and an Exception will be thrown if a duplicate is ever detected. If you are creating your own database, you should perform the check.

      1 Reply Last reply
      0
      • S saludalabs

        I have a question about GUID. I created a calender admin program that stores event data in an xml file. The xml file consist of an element called call ID. I am using ID as a key. Each event has a unique id. My code generates a GUID for each new event. Currently I set up a method in my code behind to see if the GUID exist before I except the value of the new GUID. My understanding the sytem should generate a unique GUID each time you create one. I am thinking it is possible to get a duplicate GUID value, for example if I move the application to a new server. Is this good practice or just a waste of resources? Thanks, David

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        According to MSDN (Remarks)[^], GUIDs are as globally unique as possible. The probability of seeing two the same in the world (universe?) is very low. The probability of seeing two the same on a single PC is infinitesimal. Your process looks fine, if you hit a duplicate then just generate a new one and continue. Alternatively you may like to consider a simpler key, such as time and date, sequence number, combination of the two etc. It all depends on how many items you expect to be storing.

        S 1 Reply Last reply
        0
        • L Lost User

          According to MSDN (Remarks)[^], GUIDs are as globally unique as possible. The probability of seeing two the same in the world (universe?) is very low. The probability of seeing two the same on a single PC is infinitesimal. Your process looks fine, if you hit a duplicate then just generate a new one and continue. Alternatively you may like to consider a simpler key, such as time and date, sequence number, combination of the two etc. It all depends on how many items you expect to be storing.

          S Offline
          S Offline
          saludalabs
          wrote on last edited by
          #4

          I ended up rewriting an old calendar app because of the duplicate key problem. I will leave the duplicate check code in thier just in case, it seems like the fastest solution. The amount of data depends on the client, I have some clients who enter large amounts of event, in those cases I push them to using sql server.

          T 1 Reply Last reply
          0
          • S saludalabs

            I ended up rewriting an old calendar app because of the duplicate key problem. I will leave the duplicate check code in thier just in case, it seems like the fastest solution. The amount of data depends on the client, I have some clients who enter large amounts of event, in those cases I push them to using sql server.

            T Offline
            T Offline
            The Man from U N C L E
            wrote on last edited by
            #5

            I once managed to get SQL 2005 to generate duplicate GUIDs. My insert statement managed to generate set of three identical GUIDs pretty consistently. Unfortunately we could never replicate this outside of our, rather large, application and so ended up just doing it differently. It was probably to do with the records being generated within the same millisecond, and so not that likely in most applications. So, yes you should definitely check. While in theory you should never get duplicates I have had them to often.

            If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups