close database connection gracefully on exit