|
Sample Application
The purpose of the sample application is to demonstrate the basic use of MTS with a DB2 UDB for iSeries database. This application is based on the MTS sample that is shipped with DB2 UDB for Windows NT® product. A few adjustments have been made to code for it to work with the iSeries database. The application consists of two Visual Basic projects:
- db2com.vbp — Demonstrates how to update a database using the Microsoft Transaction Server
- db2mts.vbp — Uses the Microsoft Transaction Server to call the server DLL created from db2com.vbp
db2com.vbp
As stated above, the Visual Basic project, db2com.vbp, demonstrates how to update a database using the Microsoft Transaction Server. It creates a server DLL used by the client program. This program uses a temporary table, DB2MTS, that is created in the sample database which needs to be journaled.
The components that will be deployed on MTS must follow certain programming techniques. First, a component needs to connect to the database. The ADO interface is used in the Visual Basic sample to communicate with the back-end database. The ADO requires that the data source, DB2 UDB for iSeries in this case, supports the OLE DB interface; therefore, the Microsoft OLEDB-ODBC bridge (MSDASQL) is used in this configuration to map the OLE DB calls to the ODBC calls. The MSDASQL allows ADO to connect to any ODBC data source. Here is a code snippet illustrating how to obtain an iSeries database connection:
strConnect = "Provider=MSDASQL;DSN=" + DataSource.Text + ";UID=" + UserID.Text + ";PWD=" + Password.Text
With adoConn
.CursorLocation = adUseClient
.ConnectionString = strConnect
.Open
End With
As mentioned earlier, MTS provides the connection pooling through the ODBC Driver Manager. Therefore, the number of active connections to the database can be significantly reduced. Once properly configured, the connection pooling is transparent to the client application and is managed by the ODBC Driver Manager. It is required, however, that when making a new connection; the application uses the same connection information such as user ID and password.
The MTS, through its transaction manager MS DTC, also handles distributed transactions. The transaction support property for a component can be set directly in the Visual Basic project. For instance, the transaction property for both components contained in the db2com.vbp project is set to Requires Transaction. This setting instructs MTS to use an existing transaction if available or to start a new transaction if one does not exists at the time the component is instatiated. Here is the setting for the UpdateRow component as shown in the Visual Basic project:

The transaction property for a component can also be set on the component's Properties dialog once the component was installed in MTS. The components are managed through Transaction Server Explorer.
db2mts.vbp
As stated earlier, db2mts.vbp is a Visual Basic project for a client program that uses the Microsoft Transaction Server to call the server DLL created from the Visual Basic project, db2com.vbp.
Installing the sample application
There are several basic steps required to set up an application that uses remote components running under the control of MTS.
Creating the COM component
Here are the steps for creating the COM component:
- Open the db2com.vbp project. Click Project --> References and make sure that the reference to Microsoft ActiveX Data Objects and Microsoft Transaction Server Type Library exist. If you are using COM+ on Windows 2000, you need to select COM+ Services Type Library.
- Make sure that the Threading Model is Apartment Threaded.
- Compile the project into DLL. Once the DLL is built, set the binary compatibility by clicking Project --> Properties --> Component dialog.
Creating the Client Application
Then you need to create the client application. To do so:
- Open the db2mts.vbp project. Add a reference to the server component previously created . Select Project --> References and check the box containing the MTS component created in the step above.
- Compile the project into EXE .
Installing the Component into MTS
Now you need to install the components into MTS.
- If you are using Microsoft Windows NT start the Transaction Server Explorer (on Windows 2000 select Programs --> Administrative Tools --> Component Services). Create an empty package, for instance db2mts, under Packages Installed (under COM+ Applications under Windows 2000). Import the db2com.dll functions into the newly created package.
- Use the MTS Explorer (Component Services on Windows 2000) to start MS DTC service, if is not already started.
Now you should be able to successfully run the db2mts client application on the Windows server computer.

[ Prev | Next ]
|