COM+ Transactions

COM+ Transactions

    (Windows Forms Application)

This document contains the release information for the .NET Framework COM+ Transactions sample. You will find the following sections below:

Overview

This sample demonstrates some aspects of COM+ Transactions in a .NET Framework application. The sample retrieves a value from the database, then it allows the user to update the value. After the user specifies a new value and selects AutoCompletePost or Post the sample updates the database. Then the sample checks to see if the value entered is permitted (it must be a number =>0 and <=10). If the value is not permitted, the sample aborts the transaction and otherwise commits. Finally the sample shows what the new value in the database is.

Topics

The following bullets briefly describe the technologies used by this sample.

Location

This sample is located in the Technologies\ComponentServices\Transactions subdirectory of the .NET Framework SDK samples directory.

For Example:

C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\Transactions

Building the Sample

In order to properly build and run this sample, the following steps need to be performed.

Type BuildAll.bat from the command line.

For Example:

C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\Transactions>buildall.bat

You'll also need to setup the database yourself when building from Visual Studio 7.

For Example:

C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\Transactions\CS>osql -E -S (local)\NetSDK -i TxDB.sql

If you're building the sample from Visual Studio 7, you will need to install the TxDemoSvr.dll assembly to the Global Assembly Cache before running the sample. Note: The gacutil.exe program is located in the SDK\v1.1\Bin directory.

For Example:

C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\Transactions\CS>gacutil -i TxDemoSvr.dll

The sample builds a C# and VB version of the client application and COM+ component. Source code for each language is stored in subdirectories named \CS and \VB. The C# component has 'CS' appended to its name as viewed in the Component Services administrative tool, 'TxDemoServerCS.TxObject'. The VB version is named 'TxDemoServerVB.TxObject'. When working with the sample code, be sure to observe and/or modify the version of the COM+ component that corresponds to the client application you launch.

Review comments in the source code and build.bat files for more information on sample binary creation and registration steps.

Running the Sample

In order to run this sample, follow the instructions listed below.

  • NOTE: The COM+ .NET samples require Windows 2000 or higher in order to build and run.
  • Build the Transactions sample code following the instructions above.
  • Type TxDemo.exe from the command line.

    For Example:

    C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\Transactions\CS>txdemo.exe

  • The current value is read from the database and displayed.
  • Enter a number =>0 and <=10 in the 'New value' field. Click on the button named 'Post'.
  • The message 'About to commit the transaction' should appear. Click on 'OK'. The 'Current value' field is now updated with the value you entered.
  • Enter a number =>0 or <=10 in the 'New value' field. Click on the button named 'Post'.
  • The message 'About to abort the transaction because the new value (<yourvalue>) is either <0 or >10.' should appear. Press OK, the 'Current value' field doesn't change. This is because during the transaction the current value did change, but when the transaction was rolled back, the value was changed back to its original value.
  • Now try the same data with the 'AutoPost' button. You'll notice when the demo aborts the transaction it will throw an COMException. This is to notify the AutoComplete to do an abort.

Uninstalling the Sample

In order to uninstall this sample, follow the instructions listed below.

  • To uninstall this sample, run buildall.bat -u. or build.bat -u. The batch file will then call regsvcs and gacutil with the /u switch in order to remove the sample files from the COM+ catalog and Global Assembly Cache.

Notes

For the .Net Framework samples to function properly, your Path, Include, and Lib environment variables must be set correctly. In many cases, the SDK install program updates these environment variables for you. However, if you installed the .Net Framework SDK using Visual Studio .NET, or unselected "register environment variables" during setup, these environment variables will not be updated. You can set the Path, Include and Lib environment variables by running SDKVars.bat, located in the <SDKRoot>\Bin directory. SDKVars.bat must be executed in every command shell.