473,657 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unique Identifier

Hello all,

Was wondering if anyone could provide some info on what could be a
possible solution to a problem am having.

I have to generate a Unique Identifier in C# which I will use to
assign to a user, i dont really need the Unique Identifier's to be
sequential so i was considering using system.time.hou r +
system.time.min ute. + system.time.sec ond, but am worried about
daylight savings and also people altering the time on the host PC.

I dont really want to use a database with just one table and one
field, and i would prefer to not use a file which just saves the value
and increments by one each time i want a new Unique Identifier.

Does anyone know of a way i could get a Unique Identifier??
thanks,
Adam

Jan 31 '07 #1
4 10118
Consider using Guid structure (http://msdn2.microsoft.com/en-us/
library/system.guid.asp x)

this would be something like:
user.Id = new Guid.NewGuid();

Hope this helps,
Galin Iliev [MCSD.NET, MCPD]
www.galcho.com

Jan 31 '07 #2
My Apologies,

I should have said, i need the unique ID to be numeric as it will be
stored in a database at some stage, and i have no control on what the
ID field in the DB can be.

Thanks

Adam

Jan 31 '07 #3
Unique in what domain?

If you simply want a unique uid, what's wrong with an ID field?
Peter

"ba.hons" <ba*****@gmail. comwrote in message
news:11******** **************@ a75g2000cwd.goo glegroups.com.. .
Hello all,

Was wondering if anyone could provide some info on what could be a
possible solution to a problem am having.

I have to generate a Unique Identifier in C# which I will use to
assign to a user, i dont really need the Unique Identifier's to be
sequential so i was considering using system.time.hou r +
system.time.min ute. + system.time.sec ond, but am worried about
daylight savings and also people altering the time on the host PC.

I dont really want to use a database with just one table and one
field, and i would prefer to not use a file which just saves the value
and increments by one each time i want a new Unique Identifier.

Does anyone know of a way i could get a Unique Identifier??
thanks,
Adam

Jan 31 '07 #4
On 31 Jan 2007 02:33:19 -0800, "ba.hons" <ba*****@gmail. comwrote:
>Hello all,

Was wondering if anyone could provide some info on what could be a
possible solution to a problem am having.

I have to generate a Unique Identifier in C# which I will use to
assign to a user, i dont really need the Unique Identifier's to be
sequential so i was considering using system.time.hou r +
system.time.mi nute. + system.time.sec ond, but am worried about
daylight savings and also people altering the time on the host PC.

I dont really want to use a database with just one table and one
field, and i would prefer to not use a file which just saves the value
and increments by one each time i want a new Unique Identifier.

Does anyone know of a way i could get a Unique Identifier??
thanks,
Adam
After reading all the other suggestions given you and your responses it seems
you've rejected all the common methods of assigning unique identifiers.

Your idea that you can use the hour minute and second to do that is flawed
because in the database world generation of data can occur simultaneously. Using
the time generated method would indeed assure that you would end up with
duplicate identifiers because of the lack of resolution.

I once worked for a small company whose HR department dictated that employees be
issued employee IDs that were the last four digits of their social security
number. When I told them it wouldn't work they laughed. Two months later after
hiring an new employee we hit the first duplicate. They didn't think it was
funny after that.

Take the advice given you. You'll be glad you did.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Jan 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2703
by: Kilroy Programmer | last post by:
Is there a way to store a unique numeric identifier (say, for example, an int) into a TreeNode, so that when the TreeNode is checked (since CheckBoxes is enabled) the eventhandler AfterCheck() can examine the responsible Node's identifier to see which TreeNode triggered the event? Analyzing the Node's Text string is undesirable because it would mean performing a string compare to a set of predefined strings. This is slower and not easily...
6
3058
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub directory for each request so as to get rid of any file concurrency issue, e.g c:\working\unique-identifier1 for Request #1 c:\working\unique-identifier1 for Request #2
3
6426
by: RGow | last post by:
Hi all, I need to get a unique identifier for tables created in DB2 v8.1. I can't use the table name because I want to use the identifier as part of a trigger name and the table names are already at the maximum allowed length. Originally, I wanted to make use of the SYSCAT.TABLES.TABLEID "internal identifier" but found that it is not unique. Surely DB2 must have some unique object identifiers somewhere that can be accessed by providing
6
30702
by: Paul Bromley | last post by:
Ok - I have given up on trying to find the active IP address for a given PC. For licensing purposes I need to retrive a unique identifier from the PC that the program is installed on. The Hard disk serial number would do fine, but on Googling it seems that some of the sample code will now laways work on W2K, and not without administrator rights. Hence my question - how can I consistently get a UNIQUE PC identifier using vb.net 2003 - not...
2
6203
by: Ken | last post by:
Hi, I have a form whose control source is a view from SQL server 2005 database. The view has a primary key that is a unique identifier field with keys generated by newid() function from SQL server 2005. Anyhow when I try to view/assign the unique identifier field and debug/ use watchlist I get this "????????" for the value of the unique identifier. I am able to create a text box with this unique identifier field and view it. Its just when...
8
2068
by: DaTurk | last post by:
Hi, I was just curious how you would go about creating a unique identifier with 3 ints.
4
4242
by: Rob Stevens | last post by:
Is there some sort of unique identifier in every treenode that is consistent? I was looking at the handle of every treenode, but it appears that the handle changes everytime the tree is built. I have seen in some databases where they store the treenodes they are using some serial number of the node. I don't have a clue what that is, but can someone tell me if there is something that is unique to every node.
4
2366
by: Mufasa | last post by:
I'm looking for a way to get a truly unique identifier for a machine for our client software. I'd like to have it so that there's little or no setup by the end user. (We set up the machines and then ship them out for most cases but some of our customers do provide their own machines.) Our concern is if somebody takes one of our machines and ghosts it so they have a complete copy of the machine, it will allow them to continue working. We...
13
3703
by: mliptak | last post by:
I'm trying to implement logging in my application, so that each log message has its unique identifier, e.g. log(identifier, text) What I want to achieve is that the compiler screams if the log() with 'identifier' is also used in some other place in the code which would make the 'identifier' not unique. Is that something that can be achieved in C++? Thanks
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.