Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GUID in javascript

38 views
Skip to first unread message

Mr. x

unread,
Sep 8, 2003, 5:58:52 PM9/8/03
to
Hello,
Is there any way to make a real GUID (global unique identifier) by
javascript ?
Need a sample code, please.

Thanks :)


Dave Anderson

unread,
Sep 8, 2003, 5:53:06 PM9/8/03
to
"Mr. x" wrote:
>
> Is there any way to make a real GUID (global unique
> identifier) by javascript ? Need a sample code, please.

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.


Mr. x

unread,
Sep 8, 2003, 7:17:39 PM9/8/03
to
O.K,

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...

Dave Anderson

unread,
Sep 8, 2003, 7:08:42 PM9/8/03
to
"Mr. x" wrote:
>
> 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 ?

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/

Steve van Dongen [MSFT]

unread,
Sep 8, 2003, 9:22:14 PM9/8/03
to

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

Mr. x

unread,
Sep 9, 2003, 5:02:19 AM9/9/03
to
Thanks :)
That is the solution I need...
Is there any problem that hosting companies (with I will put my aspx code)
let me make a new guid (well, it is something on the registry) ?
Or ... other solution - the same thing, but not writing the guid to
registry...

Thanks :)

"Steve van Dongen [MSFT]" <ste...@online.microsoft.com> wrote in message
news:2paqlvkhjelv5s7pn...@4ax.com...

0 new messages