Roboticus,
I have cleaned up my code as you suggested. but my problem is still there. the records are not going into the database. It gets stuck at inserting the 1st record and then I have to kill the script with CTRL+C. the debug output I have mentioned in my original post also does not proceed beyond that point. Thanks for your time.