Updating CRM 2016 to Dynamics 365 fails with 'duplicate key' error
Today I tried to apply the Dynamics 365 update to a couple of CRM organisations that were running on v220.127.116.11. This failed and in the log file I found the following error:
dbo.SolutionBase' with unique index 'ndx_UniqueName'. The duplicate key value is (SnapshotSolution80)
Just to explain what I believe has happened here, I think that someone at Microsoft created a solution snapshot in V18.104.22.168 with the unique name SnapshotSolution80. This Snapshot Solution is removed from the DB when you apply update V22.214.171.1249.
Later, in V126.96.36.1999 the same unique name is used on a different solution snapshot and when the CRM tries to insert this record into SQL it throws the error mentioned above because you never applied update V188.8.131.529 to remove the duplicate key.
How to fix it
1 Restore DB to a CRM server running CRM V184.108.40.2069
2 Attempt to apply Update 220.127.116.119 to CRM DB. If it fails with the error:
Cannot insert duplicate key row in object 'dbo.SolutionBase' with unique index 'ndx_UniqueName'. The duplicate key value is (SnapshotSolution80)
Delete the Stored Procedure [dbo].[p_RetrieveMultipleDirectAncestors] (Don't worry, the update puts it back. ) and try to apply update 18.104.22.1689 to CRM DB again.
3 After the update succeeds, backup the DB and move it back to the CRM server with CRM V22.214.171.1249. This should apply the update.
https://community.dynamics.com/crm/f/117/t/228793 Note Shrikant Karpur's answer. This worked for me and is far less destructive than all of the other answers in that thread.
http://crmblog.dk/post/2017/01/03/Dynamics-365-Onpremise-Fejl-ved-opgradering-af-organisation.aspx Note this isn't actually the correct solution to the issue he mentions, but it did lead me down the right path so it bears mentioning. Please do not change any unique names of any solutions. You could break something important.