Fix an issue where the connection to the database would not always be successful.