Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.. I have a requirement saying.. i will call an SP from a method which fetches top 1 record from a record. I will call the method asynchronously n times(say 100). How do i ensure that i fetch 100 different records?

attaching the SP I am using..

SQL
SELECT Top 1
      Jobs2Process.Id,
      Jobs2Process.FirstName,
      Jobs2Process.LastName,
      Jobs2Process.Age
FROM
      Jobs2Process
WITH (XLOCK,READPAST)


I am getting exception if i am using both the hints as WITH (XLOCK,READPAST).. but no exception when using WITH (XLOCK)..

Can anyone please explain what is the mistake i am doing?
Posted

1 solution

Hi there,

What exception are you getting?

READPAST reads rows not locked by other transactions, and XLOCK locks the transaction rows.
Using this two options in an async call will not guarantee you distinct rows: imagine that before the n+1 call starts the n-th call finishes and unlocks it's row.
 
Share this answer
 
Comments
AVINASH NOWDURU 2-Jun-11 8:56am    
@stanciu

Exception: "Uncommitable Transaction identified at the end of batch".

Scenario:

I am using XLOCK/UPDLOCK/ROWLOCK(tried taking one at a time) with READPAST hint. when i run the same query in the SQL managementStudio i get correct output, but when i call it from the code under Transaction scope i get the exception. I am also modifying a status field for each record to ensure to get distinct record.

My question is.. Does READPAST & XLOCK/UPDLOCK/ROWLOCK(tried taking one at a time) goes with System.Transactions.TransactionScope ?

Is there any other way to get 2 distinct set of records when i call a select SP asynchronously?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900