Make sure all changes are committed and cursors are closed