异步调用数据库
问题描述:
hi ..我有一个要求说..我将通过从记录中获取前1条记录的方法来调用SP.我将异步调用该方法n次(例如100次).如何确保获取100条不同的记录?
附加我正在使用的SP ..
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..
SELECT Top 1
Jobs2Process.Id,
Jobs2Process.FirstName,
Jobs2Process.LastName,
Jobs2Process.Age
FROM
Jobs2Process
WITH (XLOCK,READPAST)
如果我同时使用两个提示作为WITH(XLOCK,READPAST)..,我将得到异常,但是使用WITH(XLOCK)时,没有异常..
谁能解释我在做什么错误?
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?
答
您好,
你有什么例外?
READPAST读取未被其他事务锁定的行,而XLOCK锁定事务行.
在异步调用中使用这两个选项并不能保证您有不同的行:想象一下,在n + 1调用开始之前,第n个调用完成并解锁其行.
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.