Question

I'm working on an application where a lot of data is inserted into an SQL database at once. I use LINQ to SQL, and have something like this as my insert operation:

foreach (var obj in objects) { context.InsertOnSubmit(obj); } context.SubmitChanges();

Here's the problem: If I get an exception (for instance, DuplicateKeyException), I've NO CLUE what object caused the problem. The only information I'm getting is that at least one of the objects contains key values that are identical to some other key in the database.

Is it possible to extract more information about what object(s) caused the conflict?

Of course, I could call SubmitChanges after each and every InsertOnSubmit, but with the amount of data I'm inserting, this is incredibly slow.

Anyone have any tips for me? Thanks!

Was it helpful?

Solution

Friend, I'm not trying to be a smart alec, and perhaps I am succeeding anyways, but my main suggestion is that you abandon linq for use in data loads. SSIS produces simple, efficient and easy to maintain code for ETL work. Reason being, it was designed to do just that.

Secondly, you don't specify what type of exception is being thrown, nor if that exception when presented to you contains a non null inner exception. That's the first place I would look.

Good luck.

OTHER TIPS

I'm using Linq to sql for bulk inserts. It's slow, It's not designed for that, but it just fits nicely with my scenario.

I'm using ctx.Log to track errors. There are nice examples on http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

Also, I'm using ctx.Log to get progress bar, you might find that usefull. More details are available on my blog post http://epandzo.wordpress.com/2011/01/02/linq-to-sql-ctx-submitchanges-progress/

and stackoverflow question LINQ to SQL SubmitChangess() progress

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top