I'm inserting approximently 3 million records in a database using this solution . Eventually when the application has been inserting records for a while (my last run lasted around 4 hours), it gives a timeout with the following SqlException:
"SqlExcepetion: Timeout expired. The timeoutperiod elapsed prior to completion of the operation or the server is not responding."
What's the best way to handle this exception? Is there a way to prevent this from happening or should I catch the exception?
Thanks in advance!
If everything you have is a hammer, every problem looks like a nail.
Seriously, even TRYING to use Linq2SQL for inserting 3 million records is a broken approach. ORM's are a lot of good things, they are NOT bulk insert elements.
I suggest:
Bulk load has a lot of performance advantages. Naturally assuming you talk of something like an ETL load process here - but I fail to see a 3 million load as anything except a data warehouse / reporting / archiving style of load operation, it definitlely and per definition is not real time transaction processing ;)
Use the right tool for the job.
Generate a SQL script (or string), and execute that directly.
L2SQL is not made for mass operations like this.
I think you've to increase the CommandTimeout of your command.
Solution can be found here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.