rowlocking

How to totally lock a row in Entity Framework

风格不统一 提交于 2019-12-03 11:18:04
I am working with a situation where we are dealing with money transactions. For example, I have a table of users wallets, with their balance in that row. UserId; Wallet Id; Balance Now in our website and web services, every time a certain transaction happens, we need to: check that there is enough funds available to perform that transaction: deduct the costs of the transaction from the balance. How and what is the correct way to go about locking that row / entity for the entire duration of my transaction? From what I have read there are some solutions where EF marks an entity and then compares

SQL Server ROWLOCK over a SELECT if not exists INSERT transaction

旧时模样 提交于 2019-11-30 15:28:22
问题 I have upgraded from SQL Server 2005 to 2008. I remember that in 2005, ROWLOCK simply did not work and I had to use PAGELOCK or XLOCK to achieve any type of actual locking. I know a reader of this will ask "what did you do wrong?" Nothing. I conclusively proved that I could edit a "ROWLOCKED" row, but couldn't if I escalated the lock level. I haven't had a chance to see if this works in SQL 2008. My first question is has anyone come across this issue in 2008? My second question is as follows.

SQL Server ROWLOCK over a SELECT if not exists INSERT transaction

孤人 提交于 2019-11-30 15:02:45
I have upgraded from SQL Server 2005 to 2008. I remember that in 2005, ROWLOCK simply did not work and I had to use PAGELOCK or XLOCK to achieve any type of actual locking. I know a reader of this will ask "what did you do wrong?" Nothing. I conclusively proved that I could edit a "ROWLOCKED" row, but couldn't if I escalated the lock level. I haven't had a chance to see if this works in SQL 2008. My first question is has anyone come across this issue in 2008? My second question is as follows. I want to test if a value exists and if so, perform an update on relevant columns, rather than an

I need row-level locking

北城余情 提交于 2019-11-29 05:16:33
This is an extension to Is it possible to force row level locking in SQL Server? . Here is the use case I have accounts table having account numbers, balances, etc. This table is being used by many applications. It is quite possible that while I am modifying an account, someone else is modifying another account. So the expected behavior is that I would lock my account(ROW) and the other use will lock his(another ROW). But SQL Server 2008 R2 escalates this locking to page/table and the second user gets timeout exception. I have tried all the solutions mentioned in the referenced question but

How do I lock on an InnoDB row that doesn't exist yet?

。_饼干妹妹 提交于 2019-11-28 05:27:44
How can I guarantee that I can search if a username exists in my database, then insert that username into the database as a new row without any intercept between the SELECT and INSERT statements? Almost as if I am locking on a row that doesn't exist. I want to lock on the non-existent row with the username "Foo" , so that I can now check if it exists in the database AND insert it into the database if it doesn't already exist without any interruption. I know that using LOCK IN SHARE MODE and FOR UPDATE exist but as far as I know, that only works on rows that already exist. I am not sure what to

I need row-level locking

£可爱£侵袭症+ 提交于 2019-11-27 18:57:07
问题 This is an extension to Is it possible to force row level locking in SQL Server?. Here is the use case I have accounts table having account numbers, balances, etc. This table is being used by many applications. It is quite possible that while I am modifying an account, someone else is modifying another account. So the expected behavior is that I would lock my account(ROW) and the other use will lock his(another ROW). But SQL Server 2008 R2 escalates this locking to page/table and the second

How do I lock on an InnoDB row that doesn't exist yet?

你。 提交于 2019-11-26 22:46:27
问题 How can I guarantee that I can search if a username exists in my database, then insert that username into the database as a new row without any intercept between the SELECT and INSERT statements? Almost as if I am locking on a row that doesn't exist. I want to lock on the non-existent row with the username "Foo" , so that I can now check if it exists in the database AND insert it into the database if it doesn't already exist without any interruption. I know that using LOCK IN SHARE MODE and

How many rows will be locked by SELECT … ORDER BY xxx LIMIT 1 FOR UPDATE?

[亡魂溺海] 提交于 2019-11-26 12:58:39
问题 I have a query with the following structure: SELECT ..... WHERE status = \'QUEUED\' ORDER BY position ASC LIMIT 1 FOR UPDATE; It\'s a single-table SELECT statement on InnoDB table. Field position (INT NOT NULL) has an index on it. status is ENUM and is also indexed. SELECT ... FOR UPDATE manual page says, that it locks all rows it reads. Do I understand correctly, that in this case only one row will be locked? Or rather it will lock the whole table? Is that possible to determine which rows

Is it possible to force row level locking in SQL Server?

删除回忆录丶 提交于 2019-11-26 05:22:15
问题 I can see how to turn off row level and page level locking in SQL Server, but I cannot find a way to force SQL Server to use row level locking. Is there a way to force SQL Server to use row level locking and NOT use page level locking? 回答1: You can use the ROWLOCK hint, but AFAIK SQL may decide to escalate it if it runs low on resources From the doco: ROWLOCK Specifies that row locks are taken when page or table locks are ordinarily taken. When specified in transactions operating at the