SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Avoid duplicate numbers on massive requests

    Hello

    I have a API that gives the user a unique ID, but the API often gets simultaneous requests and ends up saving the same ID twice.

    Set getfilename = conn.Execute("SELECT UIfilename FROM userimages order by UIfilename DESC")
    if not getfilename.eof then
    uniqueid = CDbl(getfilename("uniqueid"))+1
    end if
    getfilename.close


    UIuserid = userid
    uniqueid = uniqueid


    strSql= "INSERT INTO userimages (UIuserid, uniqueid) VALUES ('" & UIuserid & "', '" & uniqueid& "')"
    Conn.Execute(strSql)

    response.write uniqueid


    How would I make sure that each record would always hold a unique number?
    thanks

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have to use the database record key as the unique id. Lock the database when you perform the assignment, then unlock when done.

    These are always unique but can be guessed by a hacker. Or you have to generate a unique key and save it.

    To generate a unique key, you can take the database record key and append a random value to it. These will also always be unique and cannot be guessed by a hacker


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •