I should really have checked if the database is opened before using it...