Click here to Skip to main content
15,880,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,
I have to migrate more then 50,000 of records from 1 table to other depending on a particular where condition in the query.
For doing this I have used a Reader object and read from the source table and trying to insert the read data to my destination table.

The logic goes well till 35,000 records.But afterwards it gives me Object Reference Error .
Please Help. :((
Rob Grainger 3-Mar-11 13:54pm    
Can you post the code you're using, or if not something representative?

I think you do not want to use reader to copy some records from one table to other. You can use an SQL statement something like

insert into DestTable(Col1, Col2)
select Col1, Col2 from SourceTable where Col3 = 'some value'
Share this answer
Costica U 3-Mar-11 21:14pm    
My 5.
I agree!
Only explanation for this is memory leakage but generally it does not happens in manged code. you can use some memory analyzer tools available on the net to see what is causing the problem.

Other suggestion is read all the rows from tables first and store in some sort of object(to DataTable) and save it once.And if your database is SQLServer i would suggest you to use SQL Loader class it is much faster for doing bulk load(if you have some triggers on insert this will not work)
Share this answer
This is just me, but I'd never use an application to move data from one table to another if I have SQL Server, you can do what Sreejith says or you can try bulk copy the table, SQL has some features really easy to use for this
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900