Microsoft KB Archive/252707

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


Violation of PRIMARY KEY Constraint Error in Browser when Checking Out

Article ID: 252707

Article Last Modified on 6/29/2004



APPLIES TO

  • Microsoft Site Server 3.0 Commerce Edition



This article was previously published under Q252707

SYMPTOMS

When a shopper attempts to check out, he or she may receive the following error message:

Violation of PRIMARY KEY constraint 'PK_(sitename)_receipt'. Cannot insert duplicate key in object '(sitename)_receipt'

CAUSE

This error can be caused by executing the purchase pipeline (from xt_orderform_purchase.asp) to complete an order but then not calling the DeleteData method, following, after the purchase has been completed successfully.

MSCSOrderFormStorage.DeleteData(null, mscsOrderForm)
                


The DeleteData method removes the purchased basket from the (sitename)_basket table. If the basket is not removed but the contents of the basket were purchased, the next time the shopper visits the site he or she will see the contents of the old basket (the previously purchased contents). If the shopper then "empties" the basket and adds new items to the basket and tries to check out using this old basket, the error will result.

This behavior occurs because the receipt table has the basket's "order_id" as its primary key. If a new basket/order_id is not generated for the shopper after each successful purchase, the shopper will unknowingly be using the old basket/order_id that has already been inserted into the receipt table (during a previous check-out) and thus he or she receives the primary key constraint violation error during execution of the "SaveReceipt" component in the purchase pipeline.

Note that if you turn on transacted pipeline logging, you will see this error in the pipeline log during execution of the "SaveReceipt" component.

RESOLUTION

This condition does not arise on any of the default sample sites or on custom wizard-generated sites. It seems that this error can only occur because of a failure to call the MSCSOrderFormStorage.DeleteData method after each successful purchase. You should check the logic of your xt_orderform_purchase.asp to ensure that the DeleteData method is called after each successful purchase to resolve this issue.

STATUS

Steps to reproduce this behavior:

  1. Open up your site's xt_orderform_purchase.asp page.
  2. Do a find for MSCSOrderFormStorage.DeleteData(null, mscsOrderForm) and type the word REM in front of that line.
  3. Save the xt_orderform_purchase.asp page.
  4. Visit the site and add items to your basket. Check out.
  5. After checking out, revisit the site and view your basket. Note that the items from the previous purchase are still listed in your basket.
  6. Empty your basket, add new items to your basket, and attempt to check out again. You should receive the error.


Keywords: kbprb KB252707