Application process connection states
In a distributed unit of work, an application process can be in a connected or unconnected state. Depending on the state, the application process can execute only certain SQL statements successfully.
A connection to a different database server can be established by the explicit or implicit execution of a CONNECT statement. The following rules apply:
- An application process cannot have more than one SQL connection to the same database server at the same time.
- When an application process executes a SET CONNECTION statement, the specified location name must be in the set of existing connections of the application process.
- When an application process executes a CONNECT statement and the SQLRULES(STD) bind option is in effect, the specified location must not be in the set of existing connections of the application process.
If an application process has a current SQL connection, the application process is in a connected state. The CURRENT SERVER special register contains the name of the database server of the current SQL connection. The application process can execute SQL statements that refer to objects managed by that server. If the server is a Db2 subsystem, the application process can also execute certain SQL statements that refer to objects managed by a Db2 subsystem with which that server can establish a connection.
An application process in an unconnected state enters a connected state when it successfully executes a CONNECT or SET CONNECTION statement.
If an application process does not have a current SQL connection, the application process is in an unconnected state. The CURRENT SERVER special register contains blanks. The only SQL statements that can be executed successfully are CONNECT, RELEASE, COMMIT, ROLLBACK, and any of the following local SET statements.
- SET CONNECTION
- SET CURRENT APPLICATION ENCODING SCHEME
- SET CURRENT PACKAGE PATH
- SET CURRENT PACKAGESET
- SET host-variable = CURRENT APPLICATION ENCODING SCHEME
- SET host-variable = CURRENT PACKAGESET
- SET host-variable = CURRENT SERVER
Because the application process is in an unconnected state, a COMMIT or ROLLBACK statement is processed by the local Db2 subsystem.
An application process in a connected state enters an unconnected state when its current SQL connection is intentionally ended, or the execution of an SQL statement is unsuccessful because of a failure that causes a rollback operation at the current server and loss of the SQL connection. SQL connections are intentionally ended when an application process successfully executes a commit operation and either of the following are true:
- The SQL connection is in the release-pending state.
- The SQL connection is not in the release-pending state, but it
is a remote connection and either of the following are true:
- The DISCONNECT(AUTOMATIC) bind option is in effect
- The DISCONNECT(CONDITIONAL) bind option is in effect and an open WITH HOLD cursor is not associated with the connection
An implicit CONNECT to a default Db2 subsystem is executed when an application process executes an SQL statement other than COMMIT, CONNECT TO, CONNECT RESET, SET CONNECTION, RELEASE, or ROLLBACK, and if all of the following conditions apply:
- The CURRENTSERVER bind option was specified when creating the application plan of the application process and the identified server is not the local Db2.
- An explicit CONNECT statement has not already been successfully or unsuccessfully executed by the application process.
- An implicit connection has not already been successfully or unsuccessfully executed by the application process. An implicit connection occurs as the result of execution of an SQL statement that contains a three-part name in a package that is bound with the DBPROTOCOL(DRDA) option.
If the implicit CONNECT fails, the application process is placed in an unconnected state.
When a connection is ended, all resources that were acquired by the application process through the connection and all resources that were used to create and maintain the connection are returned to the connection pool. For example, if application process P placed the connection to application server X in the release-pending state, all cursors of P at X are closed and returned to the connection pool when the connection is ended during the next commit operation.
When a connection is ended as a result of a communications failure, the application process is placed in an unconnected state.
All connections of an application process are ended when the process ends.