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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

1040 - product job sync failing at POS. Violation of unique key constraint error.

(0) ShareShare
ReportReport
Posted on by 137

Upon syncing the 1040 products job from AX to POS, the job is failing with the below error from event viewer. Any idea on the root cause and possible solution?

Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.ProcessTargetRequestHeaderException: ProcessTargetRequestHeader failed to execute all write requests. ---> Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.ProcessWriteRequestException: Write request on table:[ax].[RETAILASSORTMENTLOOKUP] failed to execute. ---> Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.RunException: Run() failed while performing write operation on table. ---> Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.PerformWriteOperationException: Query: MERGE [ax].[RETAILASSORTMENTLOOKUP] AS dst
USING (SELECT [ASSORTMENTID],[CREATEDDATETIME],[LINETYPE],[PRODUCTID],[RECID],[VALIDFROM],[VALIDTO],[VARIANTID] FROM [#ax_RETAILASSORTMENTLOOKUP_89d28139-c661-4b6f-b548-8be38ea3e407]) AS src
ON (dst.[RECID]=src.[RECID])
WHEN MATCHED THEN
  UPDATE SET [ASSORTMENTID]=src.[ASSORTMENTID],[CREATEDDATETIME]=src.[CREATEDDATETIME],[LINETYPE]=src.[LINETYPE],[PRODUCTID]=src.[PRODUCTID],[VALIDFROM]=src.[VALIDFROM],[VALIDTO]=src.[VALIDTO],[VARIANTID]=src.[VARIANTID]
WHEN NOT MATCHED THEN
  INSERT ([ASSORTMENTID],[CREATEDDATETIME],[LINETYPE],[PRODUCTID],[RECID],[VALIDFROM],[VALIDTO],[VARIANTID])
  VALUES (src.[ASSORTMENTID],src.[CREATEDDATETIME],src.[LINETYPE],src.[PRODUCTID],src.[RECID],src.[VALIDFROM],src.[VALIDTO],src.[VARIANTID]);
DROP TABLE [#ax_RETAILASSORTMENTLOOKUP_89d28139-c661-4b6f-b548-8be38ea3e407];
 ---> System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint 'I_1305966847_-835757873'. Cannot insert duplicate key in object 'ax.RETAILASSORTMENTLOOKUP'. The duplicate key value is (5637144576, 5637239078, 0, 1).
The statement has been terminated.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.SCSqlWriteRequestRunner.PerformWriteOperation(SqlConnection connection, SqlTransaction transaction)
   --- End of inner exception stack trace ---
   at Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.SCSqlWriteRequestRunner.PerformWriteOperation(SqlConnection connection, SqlTransaction transaction)
   at Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.SCSqlWriteRequestRunner.Run(SqlConnection connection, SqlTransaction transaction)
   --- End of inner exception stack trace ---
   at Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.SCSqlWriteRequestRunner.Run(SqlConnection connection, SqlTransaction transaction)
   at Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.SCSqlTargetRequestHandler.ProcessWriteRequest(SqlConnection connection, SqlTransaction transaction)
   --- End of inner exception stack trace ---
   at Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.SCSqlTargetRequestHandler.ProcessWriteRequest(SqlConnection connection, SqlTransaction transaction)
   at Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.SCSqlTargetRequestHandler.ProcessTargetRequestHeader(ISCTargetRequestHeader targetRequestHeader)
   --- End of inner exception stack trace ---
   at Microsoft.Dynamics.Retail.StoreConnect.Request.SQLHandler.SCSqlTargetRequestHandler.ProcessTargetRequestHeader(ISCTargetRequestHeader targetRequestHeader)
   at Microsoft.Dynamics.Retail.SynchClient.Core.DownloadAgent.ApplySessionFileToClientDatabase(SessionManager sessionMgr, String fileName)
I have the same question (0)
  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: 1040 - product job sync failing at POS. Violation of unique key constraint error.

    Hi,

    Can you share details of your AX2012 version?

    Also, can you let us know if this is the first time you see this problem / error?

    Many thanks,

    Ludwig

  • Suggested answer
    A.Prasanna Profile Picture
    8,223 on at
    RE: 1040 - product job sync failing at POS. Violation of unique key constraint error.

    Hi Vysakh,

    refer below thread

    community.dynamics.com/.../retail-synchronisation-issue-cannot-insert-duplicate-key-row

    if you facing same issue even after above solution then try to re create /provision  POS database and Run full sync.

    Regards,

    AP

  • Vysakh Profile Picture
    137 on at
    RE: 1040 - product job sync failing at POS. Violation of unique key constraint error.

    Yes, this is the first time we are seeing this error. It is only affecting around 10 stores out of the 50+ stores.

    AX 2012 version is 6.3.4000.2689 (kernel) and 6.3.3000.111(application).

  • Suggested answer
    Xusheng Profile Picture
    on at
    RE: 1040 - product job sync failing at POS. Violation of unique key constraint error.

    Hi,

    Did you check your channel DB for table "ax.RETAILASSORTMENTLOOKUP'"?

    This is the error message: Cannot insert duplicate key in object 'ax.RETAILASSORTMENTLOOKUP'. The duplicate key value is (5637144576, 5637239078, 0, 1).

    I suggest you check AX DB for table "dbo.RETAILASSORTMENTLOOKUP" to see is there any duplicate record for it.

    Another suggestion is log a service request to cooperate with Microsoft support team for it.

    Hope this can help you. :)

  • Verified answer
    Vysakh Profile Picture
    137 on at
    RE: 1040 - product job sync failing at POS. Violation of unique key constraint error.

    Hi Xusheng,

    We managed to resolve it by deleting the records from ax.RETAILASSORTMENTLOOKUP and then scheduling a full sync from AX only for this table (by creating a new scheduler job).

    Our only concern is how this issue happened and how we can avoid it in future. Any ideas on a probable root cause for such errors?

  • Suggested answer
    Xusheng Profile Picture
    on at
    RE: 1040 - product job sync failing at POS. Violation of unique key constraint error.

    It is difficult to find the RCA. Maybe relate to do process assortment and run sync job much more times.

    Do full data sync is another way to fix it.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,004

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 582 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans