disconnect

Description

Closes one or more connections to a Adaptive Server.

Syntax

exec sql disconnect 
 {connection_name | current | DEFAULT | all};

Parameters

connection_name

The name of a connection to be closed.

current

Specifies that the current connection will 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

#include <stdio.h>
 
 exec sql include sqlca;
 
 main()
 {
         exec sql begin declare section;
         CS_CHAR servname[31], username[31],
         password[31], conname[129];
         exec sql end declare section;
 
         exec sql whenever sqlerror call error_handler();
         exec sql whenever sqlwarning call error_handler();
         exec sql whenever not found continue;
 
         printf ("Username: ");
         gets   (username);
         printf ("Password: ");
         gets   (password);
         printf ("Adaptive Server name: ");
         gets   (servname);
         printf ("Connection name: ");
         gets   (conname);
 
 /*
 ** Make a named connection.
 */
         exec sql connect :username identified by :password
                 at :conname using :servname;
 /*
 ** Make an unnamed (default) connection.
 */
         exec sql connect :username identified by :password
                 using :servname;
 /*
 ** The second (default) connection is the current connection.
 */
         exec sql disconnect current;
 /*
 ** We now have neither a default connection nor a current one.
 */
         exec sql disconnect :conname;
 /*
 ** Now there are no open connections.
 */
         exec sql exit;
 }
 
 error_handler()
 {
         printf("%d\n%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
         exit(0);
 }

Usage

See also

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