SetTransPool

Description

Sets up a pool of database transactions for an application. SetTransPool allows you to minimize the overhead associated with database connections and also limit the total number of database connections permitted.

Applies to

Application object

Syntax

applicationname.SetTransPool ( minimum, maximum, timeout )

Argument

Description

applicationname

The name of the application object for which you want to establish a transaction pool

minimum

The minimum number of transactions to be kept open in the pool

maximum

The maximum number of transactions that can be open in the pool

timeout

The number of seconds to allow a request to wait for a connection in the transaction pool

Returns

Integer. Returns 1 if it succeeds and -1 if an error occurs.

Usage

Transaction pooling maximizes database throughput while also controlling the number of database connections that can be open at one time. By establishing a transaction pool before connecting to the database, an application can reuse connections made to the same data source.

When an application connects to a database without using transaction pooling, PowerBuilder physically terminates each database transaction for which a DISCONNECT statement is issued. When transaction pooling is in effect, PowerBuilder logically terminates the database connections and commits any database changes, but does not physically remove them. Instead, the database connections are kept open in the transaction pool so that they can be reused for other database operations.

Before reusing a connection in the transaction pool, PowerBuilder checks to see that the database parameters specified in the incoming connection request match those specified by one of the connections in the pool. A match occurs when both transaction objects specify the same DBMS, ServerName, LogID, LogPass, Database, and DBParm values.

The minimum value specified in the SetTransPool function must be less than or equal to the maximum value. When the minimum value is less than the maximum and the number of transactions in the pool is greater than the minimum, PowerBuilder physically terminates connections for which a DISCONNECT statement is issued until the minimum number is reached.

The maximum value specified for a transaction pool limits the total number of database connections made by the application. When the transaction pool is full, each attempt to connect will fail after the timeout interval has been exceeded.

To set up transaction pooling for an application, you need to issue SetTransPool before establishing any connections to the database.

Examples

Example 1

A distributed PowerBuilder server application that services a high volume of short database transactions to the same data source could issue the following statement in its application Open event:

server_app.SetTransPool(12,16,10)

Example 2

This statement specifies that up to 16 database connections will be supported through this server, and that 12 connections will be kept open once successfully connected. When the maximum number of connections has been reached, each subsequent connection request will wait for up to 10 seconds for a connection in the pool to become available. After 10 seconds, the connection will fail but no error is returned. You can use the DBHandle function to determine whether a connection is valid.

The following statement specifies that up to 8 database connections will be allowed through this server, and that all 8 will be kept open once successfully connected. When the transaction pool is full, each subsequent connection request will immediately fail:

server_app.SetTransPool(8,8,0)

See also