Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
2.0 KiB

  1. Sample: MQTRANS
  2. Purpose:
  3. C++ console app that demonstrates how to send/receive coordinated transactions that include MSMQ messages and SQL
  4. database updates. In this case, sums of money are transferred between the sender and the receiver via messages and
  5. each transaction sum is recorded in a database.
  6. Requirements:
  7. MSMQ1.0 or later
  8. SQL 6.5
  9. ODBC
  10. DS enabled computer (application fails and exits if local computer is DS disabled)
  11. Before running the sample, you must add MSMQDemo as DSN:
  12. Control Panel - Administrative tools - Data Sources (ODBC) - User DSN -
  13. - add - SqlServer - DataSourceNAme=MSMQDemo, Server=Local
  14. Overview:
  15. The mqtrans application takes a single param: either "-s" or "-r". Where "-s" specifies a sending instance of the application
  16. and "-r" specifies a receiving instance.
  17. A sending instance of the applications performs the following steps:
  18. 1. Creates a new database table "SenderAccount".
  19. 2. Locates a MSMQ queue of type MQTransTest and opens it. For simplicity, this sample assumes there's only
  20. one queue of this type. Note that the sample will fail if this assumption is wrong.
  21. 3. In a loop:
  22. Prompts the user to enter TransferSum.
  23. Creates a transaction using MS DTC.
  24. Within the transaction:
  25. Updates "SenderAccount" database (subtracts TransferSum).
  26. Sends a message to Receiver side.
  27. Commits the transaction.
  28. The loop is terminated if the user enters a zero TransferSum.
  29. 4. Cleanup.
  30. A receiving instance of the application does the following:
  31. 1. Creates database "ReceiverAccount".
  32. 2. Creates a MSMQ a local public queue (with the Transactional property) of type MQTransTest and opens it.
  33. 3. In a loop:
  34. Creates a transaction using MS DTC.
  35. Within the transaction:
  36. Receives a message from the queue (with the TransferSum).
  37. Updates "ReceiverAccount" database (adds TransferSum).
  38. Commits the transaction.
  39. 4. Cleanup.