Error on basket.SaveAsOrder()
I'm getting the following error when i save as basket as a pruchase order (basket.SaveAsOrder()):
Violation of PRIMARY KEY constraint 'PK_OrderForms'. Cannot insert duplicate key in object 'dbo.OrderForms'
it seems to be intermittent - as i can place orders fine but one other seems to get it quite regularly. Has anyone else seen thin before?
Thanks
[855 byte] By [
Alex] at [2008-1-10]
We've been getting that one too. Here's a stack trace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.CommerceServer.Internal.Orders.MtsTxHelper.ExecuteSqlCommandDataSet(String connStr, String[] commandTexts, ArrayList[] sqlParamValuesArray, Int32 timeout)
at Microsoft.CommerceServer.Runtime.Orders.PurchaseOrder.Save(Boolean deleteOrder, ITransaction trans)
at Microsoft.CommerceServer.Runtime.Orders.Basket.SaveAsOrder(ITransaction trans)
at Microsoft.CommerceServer.Runtime.Orders.Basket.SaveAsOrder()
I took a peek at the internals using Reflector and i notice that the order.orderGroupId gets assigned a NewGuid but I don't see the OrderForm getting changed anywhere....
Did you ever find out what was causing the issue? Or steps to recreate the Exception? I'm not quite sure what resolution to give the QA department. It looks like a bug in Commerce Server to me...
How do you generate the tracking number ?
Alex: I can't reproduce it consistently but it is still happening every once in awhile.
Gael: I think OrderFormId is the primary key of that table, not the tracking number...
Gael in our system the tracking number is just a nvarchar column on the purchase order table (no key or constraint on it). the error i'm getting is a violation of the PK_OrderFormId key which is on the orderform table - its just a standard rowguid in sql server. it must be trying to insert the same guid twice but as its all internal is pretty hard to debug.
Hi,
Has any answer been given to this thread? I've got this error one one out of 1000 requests but now I'm worried that I'm doing something wrong.. but it does seem to be an internal problem. here's what I know:
The SaveToOrder() method transfers all of the Marshaled data about the order from the OrderTemplatesAndBaskets table to the PurchaseOrder, OrderForms and LineItems tables in the <YourSiteHere>_Transactions database. The OrderGroupID of the Basket will NOT match the one for the PurchaseOrder. New Guids are created, however there must be some hash it used to seed guid creation because what I'm noticing is that there is a PurchaseOrder and OrderForm record but the Basket was never deleted from the OrderTemplatesAndBaskets table. Because the whole process never completed, when my user goes back to submit the basket, it sees the record in the OrderForms table and throws the PK Violation exception.
My questions are 2 fold:
If when a new Purchase Order is created, a new Guid is assigned, and no 2 guids are supposed to be the same within an organization, how can this basket attempt to create the same OrderFormID GUID each time. I would assume each time it would create a new guid and maybe duplicate the order in the system.
Finally, is there a scenario or something that I might not be doing that would prevent the cleanup of the basket record once the order is saved as a purchaseOrder?
Thanks,
Dave
I just wanted to check in and note that we are another customer that is ocassionally getting this error.
Anyone have any resolutions? Unfortunately, we cannot consistently recreate it either.
Thanks
EMS
I dont know about the internal cause of this error, but in your code, Is the order creation process enclosed inside a TransactionScope block?
I can confirm that all order related business calls are within one or more transactionscope blocks all with the same settings. If an error would have occurred, the transactionscope SHOULD have rolled back everything that it had done on the order, but since I'm seeing new records in the PurchaseOrders table AND remaining records in the ORderTemplatesAndBaskets table, I have to assume that no rollback took place, but rather some internal process failed to cleanup the basket records. I wish I had more to tell.. i only encountered this problem once.. but would be nice to know if it's a known issue or maybe something that will bite me in the rear later. 
--Dave
Under heavy load, we got this error 73 times this morning. Does anyone have any ideas or solutions for this?
I would really recommend opening a support case with PSS on this issue. This does look like some sort of SQL error being bubbled up to the Commerce Server runtime during times of heavy load.
Jeff Lynch
MVP Windows Server System - Commerce Server
http://codebetter.com/blogs/jeff.lynch
in doing some research into this today, it looks like it this is the problem:
- customer places order successfully
- Basket is saved as a PurchaseOrder
- the existing Basket is NOT deleted automatically
- customer tries to place a second order (using the same basket as before)
- SaveAsOrder fails with the error about the primary key violation.
I posted a detailed explanation of what appears to be happening months ago with regards to this problem. I find it troubling that noone from Microsoft is responding to the post, being that it isn't confined to a particular condition. I, for example, got this error only once and it was in a user testing environment where only one user was on the system. So it's not necessarily attributed to heavy load. Anyone from Microsoft care to shed some light on this?