GUID Unique identifer theory question
-
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
-
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
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.
-
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
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.
-
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.
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.
-
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.
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