Announcements
Hello,
I am using CRM Sdk with asp.net mvc and very frequently i am getting
An unhandled exception occured while processing the request.
Fault exception: Cannot insert duplicate key.in Microsoft.xrm.Sdk.Client.OrganisationServiceContext(Savechangesoptions)
But after restart azure server it is working.
Thanks in Advance
Thanks for your Reply
When using OrganizationContext make sure you clear the context after every save operation before u request SaveChanges again.
Everytime a SaveChanges is called the changes are committed to CRM and the updates received from the platform are copied to the objects in the context. To give you an example u added a new object to the context and called save - this would create the record the in CRM and also update the object with the Guid.
If the context is not cleared and you have modifications to submit the next time - this one flows through with an add operation once again and throws a Duplicate Key error since the Guid already exists and u are requesting an ADD operation for this.
Clear the context and that should fix the problem.
Sam
I checked Duplication rules also there are no such rule which i am duplicating.
Once this error came then it will come in all entites insert or update.
Thanks
Hi Praveen,
Please check if data is maintained in the cache memory, as code starts working once you restart the Azure service.
Also, check Dynamic CRM in which fields duplicate detection is enabled and then check the code if those fields are assigned with a valid value and not the duplicate value.
Please clear the value of a variable which is used to set value in the field.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,186 Super User 2024 Season 2
Martin Dráb 227,996 Super User 2024 Season 2
nmaenpaa 101,148