Overview of the CLI application initialization and termination phases

CLI applications must allocate the required resources during the initialization phase and cleanup the resources during the termination phase. The required resources include environment handle, statement handle, connection handle, descriptor handle (if required), connection to the target database and any other resources that are required to complete the required transaction.

Figure 1 shows the common function call sequences for both the initialization and termination phases.

In the initialization phase, all CLI application must allocate and initialize the environment, statement, and connection handles with the SQLAllocHandle() function. An environment handle and statement handle must be allocated before a connection handle can be created. When the handles are allocated, connection can be established to the target database in the initialization phase.

The transaction processing phase in the middle of the diagram is described in the Transaction processing in CLI overview topic.

The termination phase consists of disconnecting from the data source and freeing those handles that were allocated during the initialization phase. The connection handle must be freed before the environment handle.

Figure 1. Conceptual view of initialization and termination phases
Conceptual view of initialization and termination phases