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.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?