web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Duplicate key -error when exporting to BYOD

(3) ShareShare
ReportReport
Posted on by 306
I have recently started to get the following error with recurring BYOD export: 
""Violation of PRIMARY KEY constraint 'PK_XXXStaging'. Cannot insert duplicate key in object 'dbo.XXXStaging'. The duplicate key value is (Export across company: XXX - 17.12.2024 10.24.47.-09C1857EBD804C81884EF1BA788EC8DA, 1.0000000000000000, 150-000002, initial).". Failed to insert record into staging table. The keys of the record are DEFINITIONGROUP, EXECUTIONID, XXX, PARTITION, XXX. Duplicate records must be removed from the file prior to import."
 
The entity being exported is a custom and it's been working fine so far. It stopped working the following day when Quality update of 10.0.41 was installed so, I assume something was changed there (but may also be coincidence). 
I have truncated the entity's staging table and republished entity to BYOD, but nothing works. It complains about duplicate event when I choose to export only one record! 
I have checked that the entity works fine (with odata query) - there are no duplicates. I also exported some rows to CSV files and they work fine. Also rows gets copied to staging table just fine, but the problem is the target SQL BYOD Staging-table - the final step of the process.
 
Have anyone solved this kind of situation earlier? 
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at
    One of my clients reported similar errors starting in 10.0.40, but in all cases, there really were duplicates, although not always obvious. It seems that the problem used to be silently ignored (the export ended with Partially succeeded status and no one payed attention to it), but it was made more disruptive in 10.0.40. 
     
    It's not clear whether your problem is the same, but it could be.
     
    You mentioned you got the problem even when exporting a single record. Please run a SQL query against the entity view and check that there are duplications any unique index of XXXStaging (usually just StagingIdx, but you might have created more). Maybe you'll get a different result than in your previous tests.
  • Suggested answer
    Alireza Eshaghzadeh Profile Picture
    14,686 Super User 2025 Season 2 on at
    Hi,

    Do you know the exact record in the staging table that is causing the duplicate issue? If yes, a potential workaround could be to create a filter in the BYOD export job to exclude the problematic record.

    Here’s a suggested approach to resolve the issue:

    1. Truncate the staging table to clear the existing data.
    2. Deactivate change tracking for the entity.
    3. Unpublish the entity from BYOD.
    4. Refresh the data entity to ensure metadata is updated.
    5. Republish the entity to BYOD.
    6. Activate change tracking again for the entity.
    7. Create a new BYOD export job with the appropriate filtering criteria.
  • Migi Profile Picture
    306 on at
    Sorry for the late reply. I finally got access and permissions to the BYOD SQL and changed the primary key index for the entity's staging-table to see what's going on there. 
    I then exported one single record to BYOD and got the same error again. This time (because of new index) it wrote 1400 lines to the table and all rows had the same values in fields. So basically it wrote the same record all over again. The only thing that changed was recid value. And once again all looked good in D365 staging table. There must be something wrong with the connection to BYOD SQL.  Any ideas?
    @Martin Dráb @Alireza Eshaghzadeh​​​​​​​

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 490 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans