Fix test database connection and prevent exception before first assignment or after last assignment.