Necmi Göcek
2/9/2006 8:28:00 AM
I try your sample on custTable,
Session 1
static void N_LockTest1(Args _args)
{
CustTable ct;
;
ttsbegin;
select firstonly forupdate ct where ct.AccountNum == "00001";
pause;
ttscommit;
}
Session 2
static void LockTest2(Args _args)
{
CustTable ct;
;
ttsbegin;
select firstonly forupdate ct where ct.AccountNum == "00002";
pause;
ttscommit;
}
Session2 runs properly(without hang). While Session1 are still running I
look at SQL Servers Locks / Objects.
ProcessId LockType Mode
54 PAG IU
54 KEY U
54 TAB IX
As I understand from the Locks/Objest , Session1 has Update Lock on
AccountIdx on CustTable(FirstJob: AccountId = 0001) So Session2 will complete
its job without blocking by Session1.
--
_MIB_
"frango" wrote:
> Hi,
>
> Suppose user 1 executes the following job :
>
> MyTable1 myTable1;
> ;
>
> ttsbegin;
> select firstonly forupdate myTable1 where myTable1.Field1 == 1;
> pause;
> ttscommit;
>
> While user 1 is paused, user 2 starts the following job :
>
> MyTable1 myTable1;
> ;
>
> ttsbegin;
> select firstonly forupdate myTable1 where myTable1.Field1 == 2;
> pause;
> ttscommit;
>
> User 2's session hangs (before reaching the pause), while he tries to access
> to ANOTHER record than user 1 !
>
> On a third session (with SysSQLBlockingMSSQL form), we can see indeed that
> user 1 is locking the table (index key lock), and user 2 is waiting.
>
> I had expected that only the record selected by user 1 would be locked
> instead of the whole table. Is there a way to prevent this?
>
> Thank you in advance,
>
> PS : I know it is forbidden to ask user intervention within a transaction -
> I used pause for testing purposes.