Terminates the connection between an application and the database to which it is connected.
Syntax
DISCONNECT { 'connection_name' | CURRENT | ALL | DEFAULT } ;
Parameters
connection_name
The name of the connection as either a character literal or host variable.
CURRENT
Disconnects the current connection.
ALL
Disconnects all established connections.
DEFAULT
Disconnects the connection to the default database.
Notes
When you specify DISCONNECTconnection_name or DISCONNECT CURRENT and there is also an established connection to the DEFAULT database, the connection to the DEFAULT database becomes the current connection. If there is no DEFAULT database, there is no current connection after the SQL engine processes the DISCONNECT.
The DISCONNECT DEFAULT statement terminates the connection to the DEFAULT database. If this connection is the current connection, there is no current connection after this DISCONNECT statement is executed.
Example
This example illustrates CONNECT TO ASconnection_name and DISCONNECTconnection_name:
EXEC SQL
CONNECT TO 'progress:T:localhost:6745:salesdb' AS 'conn_1' ;
/*
** C Language and embedded SQL application processing against the
** database in the connect_string
*/
.
.
.
EXEC SQL
DISCONNECT 'conn_1' ;
The following example illustrates CONNECT TO DEFAULT and DISCONNECT DEFAULT:
EXEC SQL
CONNECT TO DEFAULT ;
/*
** C Language and embedded SQL application processing against the
** database in the connect_string
*/
.
.
.
EXEC SQL
DISCONNECT DEFAULT ;
After you issue DISCONNECT ALL there is no current connection. The following example disconnects all database connections:
EXEC SQL
DISCONNECT ALL;
The following example illustrates the CONNECT, SET CONNECTION, and DISCONNECT statements in combination using these steps:
1. CONNECT TOconnect_stringASconnection_name, which establishes a connect_string connection to the database in the connect_string; the connection has the name 'conn_1'.
2. CONNECT TO DEFAULT, which establishes a connection to the DEFAULT database and sets this connection current.
3. DISCONNECT DEFAULT, which disconnects the connection to the DEFAULT database.
4. SET CONNECTIONconnection_name, which sets the 'conn_1' connection current
5. DISCONNECT CURRENT, which disconnects the 'conn_1' connection.
/*
** 1. CONNECT TO 'connect_string'
*/
EXEC SQL
CONNECT TO 'progress:T:localhost:6745:salesdb' AS 'conn_1' ;
/*
** 2. CONNECT TO DEFAULT. This suspends the conn_1 connection
** and sets the DEFAULT connection current
*/
EXEC SQL
CONNECT TO DEFAULT ;
/*
** Application processing against the DEFAULT database
*/
.
.
.
/*
** 3. DISCONNECT DEFAULT
*/
EXEC SQL
DISCONNECT DEFAULT ;
/*
** 4. Set the first connection, conn_1, current
*/
EXEC SQL
SET CONNECTION conn_1 ;
/*
** Application processing against the database in the connect_string
*/
.
.
.
/*
** 5. DISCONNECT the conn_1 connection, which is the current connection.
*/
EXEC SQL
DISCONNECT CURRENT ;