I have a linq to sql statement that inserts records in the database. If there is a duplicate, it throws Primary key violation .
after this happens, whenever i try to execute any other statement, it repeatedly shows this error. Is this a problem of transaction not getting closed. Also how to handle transactions in a more reliable way in LINQ to SQL
Each DataContext instance tracks the instances of the mapping classes that it has seen. When you say:
myDataContext.InsertOnSubmit(myCustomer);you are registering a customer instance with this DataContext. Later, when you saymyDataContext.SubmitChanges();, the DataContext attempts to carry out all changes that it is tracking.In order to have a DataContext that is not tracking a record that it can’t insert, you should abandon this instance and new-up another one.