Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Concurrency problem..........

Author  Topic 

samratmail
Starting Member

1 Post

Posted - 2008-08-09 : 07:12:09
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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-09 : 07:22:40
the best way to deal with this is to set the id column as of identity type so that sql server will automatically generate values for it during insertion itself.
Go to Top of Page
   

- Advertisement -