Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alexey Badyl 33 posts 205 karma points
    Sep 28, 2015 @ 07:36
    Alexey Badyl
    0

    Cannot insert duplicate key in object 'dbo.TeaCommerce_CustomOrderProperty'

    Hi,

    We are using Umbraco 6.1.6 and TC 2.3.2.

    Sometimes we get the error during saving changes to DB for order. Our order contains about 10 custom properties and as result of save we get the following error:

    Exception Details: 
    System.Data.SqlClient.SqlException (0x80131904): Violation of PRIMARY KEY constraint 'PK_TeaCommerce_CustomProperty'. Cannot insert duplicate key in object 'dbo.TeaCommerce_CustomOrderProperty'. The duplicate key value is (15737fe8-975a-496d-a9f8-dc78299667ca, state).
    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.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, 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 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    at TeaCommerce.Api.Persistence.Database.Insert(String tableName, String primaryKeyName, Boolean autoIncrement, Object poco)
    at TeaCommerce.Api.Persistence.Database.Insert(Object poco)
    at TeaCommerce.Api.Persistence.Repositories.OrderRepository.Save(Order order)
    at TeaCommerce.Api.Models.Order.Save()
    

    As I mention, this error appears rarely and for different custom properties.

    Any ideas what is cause of this issue?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 28, 2015 @ 08:18
  • Alexey Badyl 33 posts 205 karma points
    Sep 28, 2015 @ 12:43
    Alexey Badyl
    0

    Hi Dennis,

    Yes, I sow it. But in our case alias name all time the same.

    And as I mention, this issue appear not all time. So about 90 % of orders processed successfully, and only 10 % failed with this issue. So this issue appears unexpectedly.

    I only have idea that this issue could happen when 2 or more threads tried to save the same order. But according to our code this shouldn't be possible.

    Best regards. Alexey

  • Anders Burla 2560 posts 8256 karma points
    Sep 29, 2015 @ 06:21
    Anders Burla
    0

    Hi Alexey

    Does it state which custom order line and value it tries to add to the DB? Maybe that can give you an idea of what happens.

  • Alexey Badyl 33 posts 205 karma points
    Oct 02, 2015 @ 12:28
    Alexey Badyl
    0

    Hi Anders,

    Can you rephrase your comment. Not fully catch what you mean.

    /Alexey

  • Anders Burla 2560 posts 8256 karma points
    Oct 05, 2015 @ 07:04
    Anders Burla
    0

    If the log/error tells which property alias and value that fails

  • Alexey Badyl 33 posts 205 karma points
    Oct 21, 2015 @ 17:20
    Alexey Badyl
    0

    Hello Anders,

    Yes, we know value and alias. But all time we get different values and different properties aliases.

    See example example of the same error but for other property:

    System.Data.SqlClient.SqlException (0x80131904): Violation of PRIMARY KEY constraint 'PK_TeaCommerce_OrderLineCustomProperty'. Cannot insert duplicate key 
    in object 'dbo.TeaCommerce_CustomOrderLineProperty'. The duplicate key value is (161525, strip). 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.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, 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 TeaCommerce.Api.Persistence.Database.Insert(String tableName, String primaryKeyName, Boolean autoIncrement, Object poco) at TeaCommerce.Api.Persistence.Database.Insert(Object poco) 
    at TeaCommerce.Api.Persistence.Repositories.OrderRepository.SaveOrderLines(Database database, Guid orderId, OrderLineCollection orderLines, Nullable`1 parentOrderLineId) at TeaCommerce.Api.Persistence.Repositories.OrderRepository.Save(Order order) at TeaCommerce.Api.Models.Order.Save() 
    

    As you can see we get same error but for other property after 2 weeks only.

    /Alexey

  • Anders Burla 2560 posts 8256 karma points
    Oct 26, 2015 @ 09:16
    Anders Burla
    0

    Hmm that is weird. Somehow the object model must lose the DB id of the row and because of that it tries to insert it again. But we have not heard that this is something that happens on all solutions. We have never seen it in any of the ones we have build.

    Hmm - so how to debug that? :)

    Kind regards

    Anders

Please Sign in or register to post replies

Write your reply to:

Draft