Improve database error loggin