Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Creating a Simple ActiveX Component

Archived content. No warranty is made as to technical accuracy. Content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This section gets you started quickly with a simple ActiveX™ component (Account). You then install, run, and monitor Account with the Microsoft Transaction Server (MTS) Explorer and a sample client (Bank).

 

viicsc

Scenario: Creating and Using a Simple ActiveX Component
First, create your component (Account) and run it in the MTS run-time environment by using the Bank client. Then, add a database connection to Account and run it again.

 

viic01

Creating the Account Component
Create a new ActiveX component, Account.

 

viic02

Creating the Bank Package
Use the MTS Explorer to create a new package for your component.

 

viic03

Installing the Account Component in the Bank Package
Use the MTS Explorer to install your component in a package.

 

viic04

Running and Monitoring the Account Component
Use the Bank client to run your component, and use the MTS Explorer to monitor it.

 

viic05

Modifying the Account Component: Add a Database Connection
Modify your component so that it connects to a database. The connection will be pooled by the ODBC resource dispenser. Then use the Bank client to re-run the modified component.

 

viicno

Application Design Notes: Sharing Resources
Learn how to efficiently share resources, such as database connections, through the MTS Resource Dispenser Manager and resource dispensers.

Scenario: Creating and Using a Simple ActiveX Component

This scenario has two implementation stages. The initial stage consists of building a simple component: the Account component. You can implement Account by creating a project (Account.vbp) with a class module (Account.cls). The Account class module exposes one method, Post, that passes back a string indicating that it was called successfully. The following illustration depicts the first stage of this scenario.

vi0501

The second stage of this scenario adds a database connection to get the appropriate account information from a database and update it. This demonstrates using a resource dispenser—in this case, the ODBC resource dispenser, which enables efficient connection pooling. The following illustration depicts the second stage of this scenario.

vi0502

The rest of this section provides step-by-step instructions for creating, installing, and running the Account component in this scenario. You can find the Microsoft Visual Basic projects for each of these steps in the Step1 through Step8 folders in the \Samples\Account.VB folder of your Microsoft Transaction Server installation.

Creating the Account Component

The first step toward building a simple application that you can use with Microsoft Transaction Server (MTS) is to create a simple ActiveX™ component DLL (VBAcct.dll); the Account component provides one method, Post.

The information presented here assumes a basic understanding of how to use Microsoft Visual Basic to create ActiveX components.

Note: You cannot install executable files (.exe) in MTS. If you have a component built as an executable file, you must rebuild it as a dynamic-link library (DLL).

To create the Account component

  1. Start Microsoft® Visual Basic™ and open the \Mts\Samples\Account.VB\Step1\Account.vbp project.

  2. Build the component as a DLL and save it as \Mts\Samples\Account.VB\Step1\VBAcct.dll.

Creating the Bank Package

To run your component in the MTS run-time environment, you need to create a package. For this scenario, you will create a package with a single component.

A package is a collection of components that you can deploy and manage as a unit. By grouping components into packages, you define the security and process boundaries for components running on a computer. The criteria for deciding how to group components into packages require achieving the optimum balance between performance, fault isolation, and load balancing.

You will create a package called Bank that will contain the Account component.

To create the Bank package

  1. On the Start menu, point to Programs, point to Microsoft Transaction Server, and then click Transaction Server Explorer.

  2. Create a new package named Bank. In the Set Package Identity dialog box, select Interactive user.

You can use the General, Security, Advanced, Identity, and Activation tabs to configure a package. For this scenario, you will use the default settings for the package you just created.

Installing the Account Component

To run your components in the Microsoft Transaction Server run-time environment, you first need to install them in a package. This means you need to install the Account component in the Bank package.

To install the Account component

  • Install the Account component into the Bank package you created in Creating the Bank Package. Use the Account component that you built in \Mts\Samples\Step1\Account.VB\VBAcct.dll.

You can use the General, Transaction, and Security tabs to configure a component. For this scenario, you will use the default settings for the component you just installed.

Running and Monitoring the Account Component

Now that you have created the Bank package and installed the Account component in the Microsoft Transaction Server Explorer, you can run the Account component with the Bank client and monitor the component status in the Explorer.

Running your component in MTS brings immediate benefits to your application, even if it doesn't implement any of the MTS APIs. Such benefits include:

  • Simplified management of your components though an easy-to-use graphical tool, the MTS Explorer.

  • Location transparency—the ability to run your components in-process, locally, or remotely.

  • Thread management and component tracking.

  • Database connection pooling through the Resource Dispenser Manager and the ODBC resource dispenser (automatically provided if you call the ODBC API).

To run and monitor your component

  1. In the left pane of the MTS Explorer, click the Components folder where you installed the Bank.Account component.

  2. On the View menu, click Status view to display usage information for the Bank.Account component.

  3. On the Start menu, point to Programs, point to Microsoft Transaction Server, and then click Bank Client.

    Arrange the windows so that you can see the Bank Client window and the MTS Explorer window simultaneously. The form will default to credit $1 to account number 1.

    Cc723272.vi0503(en-us,TechNet.10).gif

  4. In the Bank client, click the Account component.

  5. Click Submit.

    You should see the response Hello from Account.

  6. In the Bank client, change the iterations from 1 of 0 to 1 of 100 and click Submit.

    In the right pane of the MTS Explorer, you should see the values under the Objects and Activated columns change to 1 and back to 0.

Modifying the Account Component to Use the ODBC Resource Dispenser

In this section, you enhance the Account component by adding a database connection. You revise the Post method to access a database using ActiveX Data Objects (ADO) to obtain the appropriate account information. This demonstrates using a resource dispenser—in this case, the ODBC resource dispenser, which enables connections to be pooled for efficiency. You will also add a new class module, CreateTable, to the Account project.

To modify the Account component

  1. Open the \Mts\Samples\Account.VB\Step2\Account.vbp project.

  2. Build the component as a DLL and save it as \Mts\Samples\Account.VB\Step2\VBAcct.dll.

By adding a new class module, you have added a new COM component to this DLL. Therefore, you will need to delete the Account component in the Microsoft Transaction Server Explorer and then install the Account and the MoveMoney components.

To reinstall your components

  1. Remove the Account component.

  2. Add the new components.

    Use the DLL you created in \Mts\Samples\Account.VB\Step2\VBAcct.dll.

You can now run the new component by using the Bank client. You should see a response Credit, balance is $ 1. (VB).

Application Design Notes: Sharing Resources

Each time the Account object's Post method is called, it obtains, uses, and then releases its database connection. A database connection is a valuable resource. The most efficient model for resource usage in scalable applications is to use them sparingly, acquire them only when you really need them, and return them as soon as possible.

Historically, acquiring resources has been an expensive operation in terms of system performance. Many programs have adopted a strategy of acquiring resources and holding onto them until program termination. While this strategy is effective for single-user systems, building scalable server applications requires sharing these resources.

Microsoft Transaction Server provides an architecture for resource sharing through its Resource Dispenser Manager and resource dispensers. The Resource Dispenser Manager works with specific resource dispensers to automatically pool and recycle resources. The ODBC version 3.0 Driver Manager is a Microsoft Transaction Server resource dispenser, also referred to as the ODBC resource dispenser.

Although the Account component hasn't implemented any of the MTS-specific APIs, when you run it, MTS uses the ODBC resource dispenser. This happens automatically when the Post method uses ActiveX Data Objects (ADO) to access the database, because ADO in turn uses ODBC. Whenever any component running in the MTS run-time environment uses ODBC directly or indirectly, the component automatically uses the ODBC resource dispenser.

When the Account object releases the database connection, the connection is returned to a pool. When the Post method is called again, it requests the same database connection. Instead of creating a new connection, the ODBC resource dispenser recycles the pooled connection, which saves time and server resources.

The topic Building Scalable Components, shows you how to use just-in-time activation to use server resources even more efficiently, resulting in more scalable applications and improved performance.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.