By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,570 Members | 1,306 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,570 IT Pros & Developers. It's quick & easy.

Unique Identifier

P: n/a
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.hour +
system.time.minute. + system.time.second, 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
Share this Question
Share on Google+
4 Replies


P: n/a
Consider using Guid structure (http://msdn2.microsoft.com/en-us/
library/system.guid.aspx)

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

P: n/a
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

P: n/a
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.googlegr oups.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.hour +
system.time.minute. + system.time.second, 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

P: n/a
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.hour +
system.time.minute. + system.time.second, 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 discussion thread is closed

Replies have been disabled for this discussion.