Return Code 0 / Primary Key Violation

Posted by Community Admin on 04-Aug-2018 21:04

Return Code 0 / Primary Key Violation

All Replies

Posted by Community Admin on 09-Jul-2012 00:00
We are getting a return code 0 when trying to upload images to specific image libraries. It only happens to 2 out of 14.

We did some initial debugging with Fiddler and error logs and we got a 504 response for url: /Sitefinity/Services/Content/ImageService.svc/parent/8aa19bae-14a6-4ee2-aca3-9d85a93e332c/00000000-0000-0000-0000-000000000000/?itemType=Telerik.Sitefinity.Libraries.Model.Image&provider=&parentItemType=Telerik.Sitefinity.Libraries.Model.Album

We also found this error: Insert link table row failed: Telerik.OpenAccess.RT.sql.SQLException: Voilation of PRIMARY KEY constraint 'pk_sf_lbrrs_sf_prmssns_nhrtnc_'. Cannot insert duplicate key

I have no idea what caused this. I found some similar posts about this that all seem to hit dead ends or go into support tickets.

What do I need to do to fix this?

Posted by Community Admin on 11-Jul-2012 00:00
Hello Juan,

We have replied to you in the support ticket. If you wish you can share the information with the community at a later moment.

Kind regards,
Victor Velev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Posted by Community Admin on 17-Jul-2012 00:00
In our case this was happening for images and videos. If anyone has the same issue here is the SQL we used to resolve the issue.

update [YOURDATABASENAME].[dbo].[sf_lbrrs_sf_prmssns_nhrtnc_map]
    set seq = calculatedNewId
    from
    (
        select *
            from [YOURDATABASENAME].[dbo].[sf_lbrrs_sf_prmssns_nhrtnc_map] originalTable
            inner join
            (
                /*starts inner table*/
                select
                    [content_id] as 'innerTableContentId'
                    ,[sf_prmssons_inheritance_map_id] as 'innersf_prmssons_inheritance_map_id',
                    ROW_NUMBER() OVER(ORDER BY [content_id]) -1 as 'globalRowNum',
                    RowNumber,
                    valCount,
                    seq as 's',
                    ((ROW_NUMBER() OVER(ORDER BY [content_id]) -1) % valCount) as 'calculatedNewId'
                from [YOURDATABASENAME].[dbo].[sf_lbrrs_sf_prmssns_nhrtnc_map] a
                join
                (
                    select
                        [content_id] as 'innerContentId',
                        ROW_NUMBER() OVER(ORDER BY [content_id]) -1 AS 'RowNumber',
                        COUNT([content_id]) as 'valCount'
                            from [YOURDATABASENAME].[dbo].[sf_lbrrs_sf_prmssns_nhrtnc_map]
                        group by content_id
                ) b
                on [content_id] = innerContentId
                /*ends inner table */
            ) generatedTable
            on originalTable.[content_id] = innerTableContentId
            and originalTable.[sf_prmssons_inheritance_map_id] = innersf_prmssons_inheritance_map_id
            and originalTable.[seq] = s
    )
    /**/
    maintbl
    inner join [YOURDATABASENAME].[dbo].[sf_lbrrs_sf_prmssns_nhrtnc_map] newtbl
    on maintbl.[content_id] = newtbl.[content_id]
    and maintbl.[sf_prmssons_inheritance_map_id] = newtbl.[sf_prmssons_inheritance_map_id]
    and maintbl.[seq] = newtbl.[seq]
Posted by Community Admin on 18-Oct-2012 00:00
We encounter the same problem on editing or deleting images:
Type : Telerik.OpenAccess.Exceptions.DuplicateKeyException, Telerik.OpenAccess, Version=2012.2.628.2, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342
Message : Insert link table row failed: Telerik.OpenAccess.RT.sql.SQLException: Violation of PRIMARY KEY constraint 'pk_sf_lbrrs_sf_prmssns_nhrtnc_'. Cannot insert duplicate key in object 'dbo.sf_lbrrs_sf_prmssns_nhrtnc_map'. The duplicate key value is (9f2fb38d-8881-4953-a869-4ef84a258be0, 2051).


Is this solution still applicable to this problem?
Posted by Community Admin on 18-Oct-2012 00:00
Hi Ferdi,

The provided query is valid for the exception you are getting. What I would suggest however is to execute it on a backup copy of your project, before running it on the live server.

Regards,
Victor Velev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Posted by Community Admin on 19-Oct-2012 00:00
Hi, 

Thanks.
That is what I did and it has fixed my problem.

This thread is closed