Updating CRM 2016 TO Dynamics 365 Fails with 'DUPLICATE KEY' 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 V22.214.171.124 with the unique name SnapshotSolution80. This Snapshot Solution is removed from the DB when you apply update V126.96.36.1999.
Later, in V188.8.131.529 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 V184.108.40.2069 to remove the duplicate key.
How to fix it
1 Restore DB to a CRM server running CRM V220.127.116.119
2 Attempt to apply Update 18.104.22.1689 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 22.214.171.1249 to CRM DB again.
3 After the update succeeds, backup the DB and move it back to the CRM server with CRM V126.96.36.1999. 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.