I have 2 batch programs, 1 is a program that sends email and another one sends fax. They both access a table named QUEUE
.
In the email sender program, this is what happens in relation to QUEUE
. For each record in QUEUE
that satisfies criteria:
- Locks record 1 in
QUEUE
table:
select 1 from QUEUE with (UPDLOCK) where id = 1
- Process sending out of email
- Delete record 1 in QUEUE table:
delete from QUEUE where id = 1
- commit transaction (transaction is not auto-commit)
In the fax sender program, similar steps also happen, except that in step 2, we send out fax (of course).
The problem is that sometimes the delete from QUEUE
throws out an exception that it is locked. Thereby, re-sending of the emails/fax happens. I am sure that the group of records processed by these programs don't intersect.
It seems that delete tries to get an Update (U) lock on other records in the table although only one record is to be deleted. So exception happens when other transactions have locks on other records in that same table.
With that, I need to know if there's an option to make "delete" operation not acquire locks on records other than for the record it will delete. Because it seems that the problem is with the "delete" operation taking locks on other records in the table.
By the way, here are some information about the database (I'm not sure if they will help):
- Read Committed Snapshot is turned on
- Snapshot Isolation State is on