C# method to lock SQL Server table

前端 未结 4 1953
不知归路
不知归路 2021-02-14 03:31

I have a C# program that needs to perform a group of mass updates (20k+) to a SQL Server table. Since other users can update these records one at a time via an intranet website,

4条回答
  •  囚心锁ツ
    2021-02-14 03:35

    Try this: when you get records from you table (in the GetRecords() function?) use TABLOCKX hint:

        SELECT * FROM Table1 (TABLOCKX)
    

    It will queue all other reads and updates outside your transaction until the transaction is either commited or rolled back.

提交回复
热议问题