A comment by @heiko-theißen made me realize my error. I have a cron job that tries to update my db every midnight. That is what must have resulted in the database locked error in my program.