Thanks :)
var CN = Server.CreateObject("ADODB.Connection")
CN.Open( your SQL Server connection string )
var RS = CN.Execute("SELECT NEWID() AS GUID")
Response.Write(RS.Fields("GUID").Value)
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
In what database does this script is good for ?
I am using access in aspx, and the
"select newid() as guid" doesn't work in access.
Isn't any general solution, with no database ?
Thanks :)
"Dave Anderson" <GTSPXO...@spammotel.com> wrote in message
news:OR4taOld...@TK2MSFTNGP12.phx.gbl...
There is no such thing as a GUID without a data store to check uniqueness
against. That does not have to be a DB, but it does have to be a data store.
A DB is preferable, since it generally knows how to enforce uniqueness
across multiple simultaneous requests.
You can construct your own GUID using a random/pseudorandom generator, but
then you have to accept the possibility of duplication. As you may have
figured out, the uniqueness constraint makes this a non-trivial task.
Besides the guarantee of uniqueness from SQL Server, you get "randomness" as
a bonus. Try coding the two on your own -- not a pretty task, if you ask me.
If I were being bent over a barrel, I suppose I would construct a number by
capturing the system time (new Date().valueOf()) for the first few digits,
then pad the remaining ones with "randomly" generated numbers. I would then
use fast exponentiation to take that number to a large power over an even
larger finite field (the integers mod p for some large prime p, for
example). This would require me to implement multiple-precision arithmetic
in scripting, but I'm sure I could find examples of it on the web**.
All in all, I would have a fairly decent expectation of randomness and
uniqueness, though no guarantee of either. The DB approach would at least
guarantee me one of them, and that one has the merit of being part of the
GUID acronym itself.
But if you want to implement GUIDs on your own, suit yourself.
**Here's a client-side implementation of RSA, which includes an
implementation of multi-precision arithmetic, as well as fast
exponentiation: http://www.ohdave.com/rsa/
Try this out...
guid = new ActiveXObject("Scriptlet.TypeLib").guid.substring(0, 38);
If you need multiple GUIDs you need to create multiple objects.
Regards,
Steve
--
Please post questions to the newsgroup; everyone benefits.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sample code subject to http://www.microsoft.com/info/cpyright.htm
Thanks :)
"Steve van Dongen [MSFT]" <ste...@online.microsoft.com> wrote in message
news:2paqlvkhjelv5s7pn...@4ax.com...