AIF Deadlock

I have 4 AIF service that update multiple table and a same table.
I got the message “Cannot select a record in ChacalFolderControl (ChacalFolderControl).
Deadlock, where one or more users have simultaneously locked the whole table or part of it.” .
The code is :
try
{
select pessimisticlock tNomRepere from chacalfoldercontrol where chacalfoldercontrol.tNomDossier ==
chacalbom.tNomDossier && chacalfoldercontrol.tNomRepere == chacalbom2.tNomRepere;
if (chacalfoldercontrol.tNomRepere != ‘’)
{
ttsBegin;
chacalfoldercontrol.POKComposant = true;
chacalfoldercontrol.update();
ttsCommit;
}
else
{
ttsBegin;
chacalfoldercontrol.tNomDossier = chacalbom.tNomDossier;
chacalfoldercontrol.tNomRepere = chacalbom2.tNomRepere;
chacalfoldercontrol.POKComposant = true;
chacalfoldercontrol.insert();
ttsCommit;
}

}
catch(Exception::Deadlock)
{
retry;
}

But the"retry" seems not work . Is there anyway to avoid this deadlock message ?

Thanks.

I suggest you first log more information about the deadlock in SQL Server. You’ll see what resources are locked, which queries are to blame and so on. For example, you might find that your query locks the whole table, because you don’t have a useful index there.
You can only guess without such information.