Disconnecting from a database

When you are finished working with a database, you can disconnect from it. SQL Anywhere also gives you the ability to disconnect other users from a given database; for more information about doing this in Sybase Central, see Managing connected users.

When a database server is started, it assigns a unique connection ID to each new connection to the database server. You can obtain a user's connection-id using the CONNECTION_PROPERTY function to request the connection number. The following statement returns the connection ID of the current connection:

SELECT CONNECTION_PROPERTY( 'number' );

To disconnect from a database (Sybase Central)

  1. Select a database.

  2. Choose File » Disconnect.

To disconnect from a database (SQL)

  • Execute a DISCONNECT statement.

See DISCONNECT statement [ESQL] [Interactive SQL] and DROP CONNECTION statement.

Example 1

The following statement shows how to use the DISCONNECT statement to disconnect the current connection, conn1, in Interactive SQL:

DISCONNECT conn1;
Example 2

The following statement shows how to use DISCONNECT in embedded SQL:

EXEC SQL DISCONNECT :conn-name

To disconnect other users from a database (SQL)

  1. Connect to the database as a user with DBA authority.

  2. Use the sa_conn_info system procedure to determine the connection ID of the user you want to disconnect.

  3. Execute a DROP CONNECTION statement.

Example

The following statement drops connection number 4.

DROP CONNECTION 4;