DATABASE

Opens a new database connection in unique-session mode.

Syntax

DATABASE { dbname[@dbserver] | variable | string } [EXCLUSIVE]
  1. dbname identifies the database name.
  2. dbserver identifies the IBM® Informix® database server (INFORMIXSERVER).
  3. variable can be any character string defined variable containing the database specification.
  4. string can be a string literal containing the database specification.

Usage

The DATABASE instruction opens a connection to the database server, like CONNECT TO, but without user and password specification.
MAIN
  DATABASE stores
  ...
END MAIN
It is possible to use a program variable containing the database specification.
MAIN
  DEFINE dbname VARCHAR(100)
  LET dbname = arg_val(1)
  DATABASE dbname
  ...
END MAIN

If a current connection exists, it is automatically closed before connecting to the new database.

The connection is closed with the CLOSE DATABASE instruction, or when the program ends.

The DATABASE instruction raises an exception if the connection could not be established, for example, if you specify a database that the runtime system cannot locate, or cannot open, or for which the user of your program does not have access privileges.

The EXCLUSIVE keyword can be used to open an IBM Informix database in exclusive mode to prevent access by anyone but the current user. This keyword is IBM Informix specific and should be avoided when writing a portable SQL application.

The CONNECT TO instructions allow better control over database connections; you should use these instructions instead of DATABASE and CLOSE DATABASE.

When used outside a program block, the DATABASE instruction defines the database schema for compilation. See SCHEMA for more details.