简体   繁体   中英

MS-Access outer transaction locks SQL Server table

I am converting a large MS-Access application to use SQL Server as a back-end, using mdb+DAO. So far I have reasonable success, but it's a rather nightmarish project. Now something has me stumped for the past 3 days:

In Access I have the following code snippet (adapted for brevity):

Set oWS = DBEngine.Workspaces(0)
oWS.BeginTrans: bInTrans = True
sql = "UPDATE Artikels SET Status_OP = True, Status_OPDatum = #10/04/2014# WHERE Artikelnummer = 50808"
CurrentDb.Execute sql, dbFailOnError

'>> a bunch more business logic goes here

sql = "UPDATE Artikels SET Creatiedatum = #15/11/2002 00:00:01#, Inputdatum = #11/06/2013 15:44:35#, Stockdatum = #28/02/2014 16:16:05#, [Stockdatum A] = #21/06/2011 16:28:59#, Verkoopdatum = #23/10/2013 10:35:06#, Wijzigdatum = #10/04/2014 12:47:18# WHERE Artikelnummer = 50808"
CurrentDb.Execute sql, dbFailOnError
oWS.CommitTransaction

When executing the second statement, the application locks up until SQL Server reports a transaction timeout. Immediately after executing the first statement I noticed that Sql Server puts an IX lock on table Artikels, which apparently causes the second statement to fail.

When I remove the transaction, everything runs fine. However all statements need to be part of one transaction (the rollback BL is omitted for brevity).

I've been reading a lot of isolation levels, but I feel this is not where the solution will come from. The default READ COMMITTED seems perfectly fine. Can anyone help resolve this issue?

1/ The idea is SQL Server might decide to lock the entire table in certain conditions (eg lack of resources on the server).

2/ An idea could be to store the value from UStatus_OPDatum column into a variable and then perform a single UPDATE statement.

3/ Also you should start the transaction as late as possible, so you might extract some SELECT statements from more business logic goes here and execute them before starting the transaction.

4/ Stupid question: Are you sure you are the single person is running this piece of code?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM