I’m using the following code to insert a new entry in my existing db. But the new record doesn’t get inserted. What are the options to fetch a possible exception?
What could be the reason that this doesn’t work?
Thanks,
rAyt
using (ContactManagerSampleDataDataContext db = new ContactManagerSampleDataDataContext())
{
CustomerCompany company = new CustomerCompany();
company.CompanyName = "Test";
company.IsActive = true;
company.ModifiedDate = DateTime.UtcNow;
company.SapNumber = 1;
company.CompanyId = 1;
db.CustomerCompanies.InsertOnSubmit(company);
db.SubmitChanges();
}
If
SubmitChangesis asynchronous, then thedbobject could be disposed before it has chance to finish, however, I don’t see any evidence that it is asynchronous. Perhaps wrapping theSubmitChangescall in atry/catchblock will indicate any exceptions that have occurred. You could also look at theDataContext.ChangeConflictsto see if any conflicts occurred.