Close database in HistoryTask