PC Review


Reply
Thread Tools Rate Thread

ADO.NET concurrency while inserting

 
 
wym
Guest
Posts: n/a
 
      24th Jul 2003
I have read a bit about pessimistic and optimistic concurrency but I'm not
sure if I understand it correctly.

I would like for multiusers to insert into a table, but first off the
application calls a function that querys for the max unique key of the
table. Then the application adds 1 to find the next sequential unique key.
Using this new unique key, it inserts a new record.

From what I understand of pessimistic and optimistic concurrency, they both
deal with protecting data while updating records. The problem is, I'm not
updating, I'm concurrently inserting.

Example:

User A gets a max unique key from table X which happens to be 100
User A adds a record to table X with unique key of 101 (100+1)
Meanwhile...
User B gets a max unique key from table X which also happens to be 100
User B adds a record with 101 as the unique key as well
It should be...
User B gets max unique key of 101
User B adds a record of 102

Can anyone explain how concurrent inserts are done?

Thanks in advance.


 
Reply With Quote
 
 
 
 
Stephen Muecke
Guest
Posts: n/a
 
      24th Jul 2003
wym

Why not just create an autoincrementing column in your table?
There is no need to waste valuable resources querying the table and no
concurrency issues with the unique key column
When you insert a new record, set your rows unique key column to the value
returned by @@IDENTITY

Stephen


"wym" <(E-Mail Removed)> wrote in message
news:RVHTa.7054$(E-Mail Removed)...
> I have read a bit about pessimistic and optimistic concurrency but I'm not
> sure if I understand it correctly.
>
> I would like for multiusers to insert into a table, but first off the
> application calls a function that querys for the max unique key of the
> table. Then the application adds 1 to find the next sequential unique

key.
> Using this new unique key, it inserts a new record.
>
> From what I understand of pessimistic and optimistic concurrency, they

both
> deal with protecting data while updating records. The problem is, I'm not
> updating, I'm concurrently inserting.
>
> Example:
>
> User A gets a max unique key from table X which happens to be 100
> User A adds a record to table X with unique key of 101 (100+1)
> Meanwhile...
> User B gets a max unique key from table X which also happens to be 100
> User B adds a record with 101 as the unique key as well
> It should be...
> User B gets max unique key of 101
> User B adds a record of 102
>
> Can anyone explain how concurrent inserts are done?
>
> Thanks in advance.
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Concurrency Help Jonathan Wood Microsoft ADO .NET 6 22nd May 2008 06:33 AM
Concurrency Help epigram Microsoft ADO .NET 6 17th May 2005 07:05 AM
concurrency for asp.net angus Microsoft ASP .NET 3 4th Feb 2005 10:13 AM
Concurrency in ASP.NET ElanKathir .S.N Microsoft ASP .NET 1 6th Feb 2004 09:49 PM
Concurrency in ADO.NET ravi Microsoft ADO .NET 1 23rd Dec 2003 11:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:31 AM.