+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Return Code 0 / Primary Key Violation

Return Code 0 / Primary Key Violation

6 posts, 0 answered
  1. Juan Sola
    Juan Sola avatar
    28 posts
    Registered:
    08 Jan 2007
    09 Jul 2012
    Link to this post
    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?

  2. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    11 Jul 2012
    Link to this post
    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
  3. Juan Sola
    Juan Sola avatar
    28 posts
    Registered:
    08 Jan 2007
    17 Jul 2012
    Link to this post
    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]
  4. Ferdi
    Ferdi avatar
    9 posts
    Registered:
    17 May 2012
    18 Oct 2012
    Link to this post
    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?
  5. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    18 Oct 2012
    Link to this post
    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
  6. Ferdi
    Ferdi avatar
    9 posts
    Registered:
    17 May 2012
    19 Oct 2012 in reply to Victor Velev
    Link to this post
    Hi, 

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

6 posts, 0 answered