views:

41

answers:

1

Hi! 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!

+1  A: 

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.

MaasSql
Thanks for the tip... I will look into this!
Hallgeir