Fixed database error by making sure all database is closed after opening.