I would try to commit more often, inside your loop -start by commiting every 10 rows inserted and then test making insert batch larger until you are comfortable.