Close database on shutdown