closeDb function

Finalise and close the database