Closes one or more connections to a Adaptive Server Enterprise.
exec sql disconnect {connection_name | current | DEFAULT | all};
The name of a connection to be closed.
Specifies that the current connection will 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.
#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 Enterprise 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);
}
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 Enterprise objects, releases any locks the connection has in the Adaptive Server Enterprise, and closes the network connection to the Adaptive Server Enterprise.
commit work, commit transaction, connect, rollback transaction, rollback work