Try OpenEdge Now
skip to main content
Programming Interfaces
Data Management : Database Access : Database connections : The CONNECT statement
The CONNECT statement
The CONNECT statement allows you to connect to a database from an ABL procedure or directly from the Procedure Editor. The CONNECT statement has the following syntax:


CONNECT {   physical-name      [ parameters ]
         | -db physical-name   [ parameters ]
         | -pf parameter-file  [ parameters ]
        {  -db physical-name   [ parameters ]
         | -pf parameter-file  [ parameters ]
      ]...[ NO-ERROR ]
An argument that represents the actual name of the database on a disk. The first physicalname argument you specify in a CONNECT statement does not require the Database Name (–db) parameter. All subsequent physicalnames must be preceded by the –db parameter.
The name of a parameter file that contains database connection information. See OpenEdge Deployment: Startup Command and Parameter Reference for more information on parameter files.
One or more database connection parameters. Each connection parameter applies to the most recently specified database (–db). For the parameters you can specify, see the information on client connection parameters in the OpenEdge Deployment: Startup Command and Parameter Reference.
This argument suppresses the error condition, but still displays the error message when an attempt to CONNECT to a database fails.
Although you can connect to several databases within one CONNECT statement, it is a good idea to connect only one database per CONNECT statement, because a connection failure for one database causes a termination of the current CONNECT statement. However, databases already connected when the statement terminates stay connected. In cases like this, it is a good idea to use the CONNECTED functions to see which databases were connected and which were not.
Here is an example of using a parameter file with the CONNECT statement:
In this example, the CONNECT statement uses the file to connect to the appldb1 database.
-db appldb1
A single procedure cannot connect to and then access a database. The following code fragment does not run:
/* NOTE: this code does NOT work */

CONNECT sports2000.
FOR EACH sports2000.Customer NO-LOCK:
  DISPLAY Customer.
By splitting this example into a procedure and a subprocedure, you can connect to the database in the main procedure, and then access it in the subprocedure. For example:
CONNECT sports2000.
RUN i-subproc.p.
FOR EACH sports2000.Customer NO-LOCK:
  DISPLAY Customer.
For more information on the CONNECT statement, see OpenEdge Development: ABL Reference.