The DISCONNECT statement destroys one or more connections when there is no active unit of work (that is, after a commit or rollback operation). (74)
Invocation
Although an interactive SQL facility might provide an interface that gives the appearance of interactive execution, this statement can only be embedded within an application program. It is an executable statement that cannot be dynamically prepared.
Authorization
None Required.
Syntax
(1) >>-DISCONNECT----+-server-name------+-------------------------->< +-host-variable----+ +-CURRENT----------+ | .-SQL-. | '-ALL+-----+-------'
Notes:
|
Description
If a host-variable is specified, it must be a character string variable with a length attribute that is not greater than 8, and it must not include an indicator variable. The server-name that is contained within the host-variable must be left-justified and must not be delimited by quotation marks.
Note that the server-name is a database alias identifying the application server. It must be listed in the application requester's local directory.
The specified database-alias or the database-alias contained in the host variable must identify an existing connection of the application process. If the database-alias does not identify an existing connection, an error (SQLSTATE 08003) is raised.
Rules
Notes
If the DISCONNECT statement is unsuccessful, the connection state of the application process and the states of its connections are unchanged.
If server-name or host-variable is specified in the DISCONNECT statement, it must identify the current connection because Type 1 CONNECT only supports one connection at a time. Generally, DISCONNECT will fail if within a unit of work with the exception noted in "Rules".
Examples
Example 1: The SQL connection to IBMSTHDB is no longer needed by the application. The following statement should be executed after a commit or rollback operation to destroy the connection.
EXEC SQL DISCONNECT IBMSTHDB;
Example 2: The current connection is no longer needed by the application. The following statement should be executed after a commit or rollback operation to destroy the connection.
EXEC SQL DISCONNECT CURRENT;
Example 3: The existing connections are no longer needed by the application. The following statement should be executed after a commit or rollback operation to destroy all the connections.
EXEC SQL DISCONNECT ALL;
(74) If a single connection is the target of the DISCONNECT statement, then the connection is destroyed only if the database has participated in any existing unit of work, not whether there is an active unit of work. For example, if several other databases have done work but the target in question has not, it can still be disconnected without destroying the connection.