Well, my first impression is that there is nothing wrong with the code, but that the database driver can't keep up with the changes. You are saying it goes through the loop several times before the error, right? Does the error always happen on the same record, or with a record that always contains a certain value? I would try putting in a delay after each update, and see what happens.