Connection management

How connections are managed depends on what states the SQL connection and the application process are in.

An application process is in one of four states at any time:

  • Connectable and connected
  • Unconnectable and connected
  • Connectable and unconnected
  • Unconnectable and unconnected

Initial state of an application process: An application process is initially in the connectable and connected state. The database server to which the application process is connected is determined by a product-specific option that might involve an implicit CONNECT operation. An implicit connect operation cannot occur if an implicit or explicit connect operation has already successfully or unsuccessfully occurred. Thus, an application process cannot be implicitly connected to a database server more than once. Other rules for implicit connect operations are product-specific.

Figure 1 shows the state transitions:

Figure 1. State transitions for an application process connection in a remote unit of work
Begin figure description. A diagram shows, with boxes, the four states that an application process can be in at any time. Arrows connect the boxes and indicate operations of the application process.

In the following descriptions of application process connections, CONNECT can mean:

  • CONNECT TO
  • CONNECT RESET
  • CONNECT authorization

It cannot mean CONNECT with no operand, which is used to return information about the current server.

Consecutive CONNECT statements can be executed successfully because CONNECT does not remove an application process from the connectable state. A CONNECT statement does not initiate a new unit of work; a unit of work is initiated by the first SQL statement that accesses data. CONNECT cannot execute successfully when it is preceded by any SQL statement other than CONNECT, COMMIT, RELEASE, ROLLBACK, or SET CONNECTION. To avoid an error, execute a commit or rollback operation before a CONNECT statement is executed.

Connectable and connected state: In the connectable and connected state, an application process is connected to a database server, and CONNECT statements that target the current server can be executed. An application process re-enters this state when either of the following is true:

  • The process completes a rollback or a successful commit from an unconnectable and connected state.
  • The process successfully executes a CONNECT statement from a connectable and unconnected state.

Unconnectable and connected state: In the unconnectable and connected state, an application process is connected to a database server, and only a CONNECT statement with no operands can be executed. An application process enters this state from a connectable and connected state when it executes any SQL statement other than CONNECT, COMMIT, or ROLLBACK.

Connectable and unconnected state: In the connectable and unconnected state, an application process is not connected to a database server. The only SQL statement that can be executed is CONNECT. An application process enters this state if any of the following is true:

  • The process does not successfully execute a CONNECT statement from a connectable and connected state.
  • The process executes a COMMIT statement when the SQL connection is in a release-pending state.
  • A system failure occurs during a COMMIT or ROLLBACK from an unconnectable and connected state.
  • The process executes a ROLLBACK statement from an unconnectable and unconnected state.

Other product-specific reasons can also cause an application process to enter the connectable and unconnected state.

Unconnectable and unconnected state: In the unconnectable and unconnected state, an application process is not connected to a database server and CONNECT statements cannot be executed. The only SQL statement that can be executed is ROLLBACK. An application process enters this state from an unconnectable and connected state as a result of a system failure, except during a COMMIT or ROLLBACK, at the server.