Fixed handling of database lock exceptions