The initialization tasks consist of the allocation and initialization of the environment and one or more connection objects.
There are three basic types of objects:
An application can be connected to several serves at the same time, and can establish several distinct connections to the same server. An application requires a connection object for each connection to a database server. For information on multiple connections, refer to Connecting to one or more data sources.
The Advanced Database feature supports three ways to connect to a data source. The simplest way is by sending the connectTo:as:password: message to the UtyDB2DatabaseManager class.
connection := UtyDB2DatabaseManager connectTo: 'SAMPLE' as: 'userid' password: 'password'.
The second way involves the use of a connection descriptor. A connection descriptor is a session independent means of storing information about a connection and its attributes. In the following example, the connection’s auto commit attribute is specified using the connection descriptor.
connection := UtyDB2DatabaseManager newConnectionDescriptor databaseName: 'SAMPLE'; userId: 'user'; password: 'password'; autoCommit: false; connect.
The third way a connection may be established is by using the DB2 CLI driver connect mechanism.
connection := UtyDB2DatabaseManager connectUsing: aConnectionString
where aConnectionString has the following format:
+-,-----------------------------------------+ V | >>----+-DSN---------------------+=--attribute--+--------------->< +-UID---------------------+ +-PWD---------------------+ +-DB2 CLI-defined-keyword-+
Each keyword above has an attribute that is equal to the following:
DSN | Data source name. The name or alias-name of the database. |
UID | Authorization-name (user identifier). |
PWD | The password corresponding to the authorization name. If there is no password for the user ID, an empty is specified (PWD=;). |
The list of DB2 CLI defined keywords and their associated attribute values are discussed in the Configuration Keywords section of the DB2 Call Level Interface Guide and Reference. Any one of the keywords in that section can be specified on the connection string. If any keywords are repeated in the connection string, the value associated with the first occurrence of the keyword is used.
If any keyword exists in the CLI initialization file, the keyword and their respective values are used to augment the information passed to DB2 CLI in the connection string. If the information in the CLI initialization file contradicts information in the connection string, the values in connection string take precedence.
Most of the objects, including the database manager, implement a close method. In all cases, the close method causes the receiving object to release its handle to its corresponding CLI data object and well as any other system resource it references, such as allocated memory.