disconnect

Description

Closes one or more connections to a Adaptive Server.

Syntax

exec sql disconnect 
 {connection_name | current | DEFAULT| all} end-exec

Parameters

connection_name

The name of a connection to be closed.

current

Specifies that the current connection is to be closed.

DEFAULT

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;
all

Specifies that all active connections be closed.

Examples

Example 1

     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.

Usage

See also

commit work, commit transaction, connect, rollback transaction, rollback work