The explicit connection

When you use the CONNECT statement to connect to a database environment, you establish an explicit connection.

The application connects directly to the database server that you specify. If you do not specify the name of a database server in the CONNECT statement, the application establishes an explicit connection to the default database server (that the ONEDB_SERVER environment variable identifies).

An explicit connection enables an application to support multiple connections to one or more database environments. Although the application can connect to several database environments during its execution, only one connection can be current at a time. Dormant connections are connections that the application has established but is not currently using. The application must have a current connection to execute SQL statements.

The following SQL connection statements establish and manage explicit connections:
  • The CONNECT statement establishes an explicit connection between a database environment and the application.
  • The SET CONNECTION statement switches between explicit connections. It makes a dormant connection the current connection.
  • The DISCONNECT statement terminates a connection to a database environment.
These connection statements provide the following benefits, which allow you to create more portable applications:
  • Compliance with ANSI and X/Open standards for database connections
  • A uniform syntax for local and remote data access for use in a distributed client-server environment
  • Support for multiple connections within a single application
Because the CONNECT, DISCONNECT, and SET CONNECTION statements include HCL OneDB™ extensions to ANSI-standard syntax, these statements generate ANSI-extension warning messages at the following times:
  • At run time, if you have set the DBANSIWARN environment variable
  • At compile time, if you have compiled the source file with the -ansi preprocessor option
The application, not the database server, processes these connection statements. Therefore, the application cannot use them in a PREPARE or an EXECUTE IMMEDIATE statement.
Important: Use of the DATABASE, CREATE DATABASE, START DATABASE, CLOSE DATABASE, and DROP DATABASE statements is still valid with an explicit connection. However, in this context, refer only to databases that are local to the current connection in these statements; do not use the @server or //server syntax.