Closing cursor after getting data to prevent connection leak