Hi,
I am working on an ASP.NET application where I need to create a unique
key in a page. When a customer clicks on the button "Generate Key" I
need to create a key which should be unique in the database. I am
plannig to create in the format MMDDYYHHMMSS.
I have written a class that generates the key:
public class GenUniqueID
{
private static readonly GenUniqueID instUnique=new GenUniqueID();
private StringBuilder strUnique=new StringBuilder(" ");
private GenUniqueID()
{
DateTime dtID=DateTime.N ow;
strUnique.Appen d(dtID.Month);
strUnique.Appen d(dtID.Day);
strUnique.Appen d((dtID.Year.To String()).Subst ring(2,2));
strUnique.Appen d(dtID.Hour);
strUnique.Appen d(dtID.Minute);
strUnique.Appen d(dtID.Second);
}
public static GenUniqueID Instance
{
return instUnique;
}
public static string UniqueID
{
get
{
return strUnique.ToStr ing();
}
}
}
I'll call this method from my aspx page :
GenUniqueID key=GenUniqueID .Instance();
string strKey=key.Uniq ueID;
Will this guarantee a UNIQUE key even if two or more users from
different locations will click on "Generate Key" at the same time???
Thanks,
Ashish.
I am working on an ASP.NET application where I need to create a unique
key in a page. When a customer clicks on the button "Generate Key" I
need to create a key which should be unique in the database. I am
plannig to create in the format MMDDYYHHMMSS.
I have written a class that generates the key:
public class GenUniqueID
{
private static readonly GenUniqueID instUnique=new GenUniqueID();
private StringBuilder strUnique=new StringBuilder(" ");
private GenUniqueID()
{
DateTime dtID=DateTime.N ow;
strUnique.Appen d(dtID.Month);
strUnique.Appen d(dtID.Day);
strUnique.Appen d((dtID.Year.To String()).Subst ring(2,2));
strUnique.Appen d(dtID.Hour);
strUnique.Appen d(dtID.Minute);
strUnique.Appen d(dtID.Second);
}
public static GenUniqueID Instance
{
return instUnique;
}
public static string UniqueID
{
get
{
return strUnique.ToStr ing();
}
}
}
I'll call this method from my aspx page :
GenUniqueID key=GenUniqueID .Instance();
string strKey=key.Uniq ueID;
Will this guarantee a UNIQUE key even if two or more users from
different locations will click on "Generate Key" at the same time???
Thanks,
Ashish.
Comment