Fix database lock problem