CLOSE DATABASE statement

Use the CLOSE DATABASE statement to close the implicit connection to the current database. This statement is an extension to the ANSI/ISO standard for SQL.

Syntax


1  CLOSE DATABASE

Usage

When you issue a CLOSE DATABASE statement, you can issue only the following SQL statements immediately after it:
  • CONNECT
  • CREATE DATABASE
  • DATABASE
  • DROP DATABASE
  • DISCONNECT

    (The DISCONNECT statement is valid here only if an explicit connection existed before CLOSE DATABASE was executed.)

Issue the CLOSE DATABASE statement before you drop the current database.

If your current database supports transaction logging, and if you have started a transaction, you must issue a COMMIT WORK or ROLLBACK WORK statement before you can use the CLOSE DATABASE statement.

The following example shows how to use the CLOSE DATABASE statement before you drop the current database to which your session had established an implicit connection:
DATABASE stores_demo;
. . .
CLOSE DATABASE;
DROP DATABASE stores_demo;

In , the CLOSE DATABASE statement cannot appear in a multistatement PREPARE operation.

If a previous CONNECT statement has established an explicit connection to a database, and that connection is still your current connection, you cannot use the CLOSE DATABASE statement to close that explicit connection. (You can use the DISCONNECT statement to close the explicit connection.)

If you use the CLOSE DATABASE statement within a UDR called by a WHENEVER statement, specify WHENEVER SQLERROR CONTINUE and WHENEVER SQLWARNING CONTINUE before the ROLLBACK WORK statement. This action prevents the program from looping endlessly if the ROLLBACK WORK statement encounters an error or a warning.

When you issue the CLOSE DATABASE statement, any declared cursors are no longer valid. You must re-declare any cursors that you want to use.

In an ANSI-compliant database, if no error is encountered while you exit from DB-Access in non-interactive mode without issuing the CLOSE DATABASE, COMMIT WORK, or DISCONNECT statement, the database server automatically commits any open transaction.