Updated on 2024-06-03 GMT+08:00

DISCONECT

Description

Closes one or all database connections.

Syntax

DISCONNECT connection_name
DISCONNECT [ CURRENT ] 
DISCONNECT DEFAULT 
DISCONNECT ALL

Parameters

  • connection_name

    Specifies the name of the database connection established by the CONNECT command.

  • current

    Closes the current connection, which can be a recently opened connection or a connection set by the SET CONNECTION command. This is also the default if no parameter is passed to the DISCONNECT command.

  • default

    Closes the default connection.

  • all

    Closes all open connections.

Examples

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) 
{ 
    /* Create the testdb database in advance. */
    EXEC SQL CONNECT TO testdb AS DEFAULT; 
    EXEC SQL CONNECT TO testdb AS con1; 
    EXEC SQL CONNECT TO testdb AS con2; 
    EXEC SQL CONNECT TO testdb AS con3; 
    EXEC SQL DISCONNECT CURRENT;  /* Close connection 3. */
    EXEC SQL DISCONNECT DEFAULT;  /* Close the default connection. */
    EXEC SQL DISCONNECT ALL;      /* Close connections 2 and 1. */
    return 0; 
}

Helpful Links

CONNECT, SET CONNECTION