Closes one or more connections to a Adaptive Server.
exec sql disconnect {connection_name | current | DEFAULT| all} end-exec
The name of a connection to be closed.
Specifies that the current connection is to be closed.
Specifies that the default connection is to be closed. This keyword must be in uppercase letters if you specify the default connection_name using a character string variable, for example:
exec sql disconnect :hv;
Specifies that all active connections be closed.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 SERV-NAME PIC X(25).
01 USER-NAME PIC X(25).
01 PASSWORD PIC X(25).
01 CONN-NAME PIC X(25).
EXEC SQL END DECLARE SECTION END-EXEC.
...
MOVE "sa" TO USER-NAME.
MOVE "" TO PASSWORD.
* Make a default connection.
EXEC SQL CONNECT :USER-NAME IDENTIFIED BY :PASSWORD END-EXEC.
EXEC SQL SELECT @@servername into :srvname END-EXEC.
DISPLAY "NOW CONNECTED TO SERVER ", srvname.
* Accept a server name from the user and make a new connection.
DISPLAY "SERVER NAME? ".
ACCEPT SERV-NAME.
EXEC SQL CONNECT :USER-NAME IDENTIFIED BY :PASSWORD
At conn2 USING :SERV-NAME END-EXEC.
EXEC SQL SELECT @@servername into :srvname END-EXEC
DISPLAY "NOW CONNECTED TO SERVER ", srvname.
* Make a third connection.
EXEC SQL CONNECT :USER-NAME IDENTIFIED BY :PASSWORD
At conn3 USING :SERV-NAME END-EXEC.
EXEC SQL SELECT @@servername into :srvname END-EXEC.
DISPLAY "NOW CONNECTED TO SERVER ", srvname.
* Now set the current connection to DEFAULT.
EXEC SQL SET CONNECTION DEFAULT END-EXEC.
* Now disconnect the first connection which is the default.
DISPLAY "DISCONNECTING DEFAULT!".
EXEC SQL DISCONNECT DEFAULT END-EXEC.
* Now sdet the current connection to connection2.
EXEC SQL SET CONNECTION conn2 END-EXEC.
* Now disconnect the third connection.
DISPLAY "DISCONNECTING THIRD!".
EXEC SQL DISCONNECT conn3 END-EXEC.
* Disconnect remaining connections - case 'conn2' will be closed.
DISPLAY "DISCONNECTING ALL!".
EXEC SQL DISCONNECT ALL END-EXEC.
By itself, the disconnect keyword is not a valid statement. Instead, it must be followed by connection_name, current, DEFAULT, or all.
Closing a connection releases all memory and resources associated with that connection.
disconnect does not commit current transactions; it rolls them back. If an unchained transaction is active on the connection, disconnect rolls it back, ignoring any savepoints.
Closing a connection closes open cursors, drops temporary Adaptive Server objects, releases any locks the connection has in the Adaptive Server, and closes the network connection to the Adaptive Server.
commit work, commit transaction, connect, rollback transaction, rollback work