Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Concurrency problem............

Concurrency problem............

Scheduled Pinned Locked Moved Database
databasecsharpasp-netsql-serversysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samrat net
    wrote on last edited by
    #1

    Hello Friend I have faced a problem in SQL Server I have a stored procedure which works as follows Declare @Id int Select @id=max(id) from emp Set @id=@id+1 update emp Set id=@id return @id Now, we call this stored procedure from our ASP.net application. It is working perfecly in single user environment, but the problem is that when we are working in multi-user environment some time the procedure returns same id instead of unique id. How can I solve it, so that every time the procedure returns unique value for each user. Is there any technique to execute this stored procedure in queue. Thanks in advance

    W 1 Reply Last reply
    0
    • S samrat net

      Hello Friend I have faced a problem in SQL Server I have a stored procedure which works as follows Declare @Id int Select @id=max(id) from emp Set @id=@id+1 update emp Set id=@id return @id Now, we call this stored procedure from our ASP.net application. It is working perfecly in single user environment, but the problem is that when we are working in multi-user environment some time the procedure returns same id instead of unique id. How can I solve it, so that every time the procedure returns unique value for each user. Is there any technique to execute this stored procedure in queue. Thanks in advance

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Hi, I would suggest that you reconsider the logic in your procedure from multi-user point of view. However, if you want to prevent simultaneous operations with this structure, simply start with the update to get an exclusive lock. For example:

      DECLARE @Id int

      UPDATE emp SET id=(SELECT MAX(id) FROM emp);
      SELECT @id=MAX(id) FROM emp;
      RETURN @id;

      Mika

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups