Closing database and cursors.