Fixed issues when database connection can't be properly established