Fix error where database is not open