>On the other side: I understand how you know which command fails to lock a record. But how do you know which command keeps the lock? (you said that the lock is set and kept by an other INSERT-SQL, how do you know it?)
I was making reference that the error line is always the INSERT INTO SQL command. It never failed on another line. However, as you stated, the place where the original lock occurs is not known at this time. But, in this table, this is the only place I update it. There is no other place in the system where I write into this table. So, I would suspect that the first application doing the INSERT INTO SQL is in effect while the second application try to get the lock.