PreviousNextIndex

CONNECT statement

Allows access to one or more databases from within an ABL procedure.

Syntax

CONNECT 
  { 
    { physical-name | VALUE ( expression ) } [ options ] | options  
  } 
  [ NO-ERROR ] 

physical-name
VALUE ( expression )
options
NO-ERROR
Examples

This procedure attempts to connect to databases mydb1 and mydb2 in single-user mode, with error suppression. You must connect to a database before you run a procedure that references it.

r-connct.p
CONNECT mydb1 -1 -db mydb2 -1 NO-ERROR. 

The following four code fragments attempt exactly the same database connection to the Sports2000 database:

CONNECT C:\OpenEdge\WRK\db\Sports2000 -H dbserver -S 1900 NO-ERROR. 

CONNECT -db C:\OpenEdge\WRK\db\Sports2000 -H dbserver -S 1900 NO-ERROR. 

CONNECT VALUE("-db C:\OpenEdge\WRK\db\Sports2000 -H dbserver -S 1900") 
  NO-ERROR. 

CONNECT VALUE("-db C:\OpenEdge\WRK\db\Sports2000 -H dbserver") -S 1900 
  NO-ERROR. 

In the next example, assume database sports2000 has not been previously connected, so the following r-cnct1.p procedure fails. At the start of execution, r-cnct1.p checks whether sports2000 is connected. If sports2000 is not connected, a run-time error occurs. As shown in the example, attempting to connect to sports2000 within the procedure does not solve the problem:

/* NOTE: this code does NOT work */ 
CONNECT sports2000 -1. 
FOR EACH sports2000.Customer NO-LOCK: 
  DISPLAY Customer. 
END. 

Instead, split r-cnct1.p into two procedures, as shown in r-dispcu.p and r-cnct2.p:

r-dispcu.p
FOR EACH sports2000.Customer NO-LOCK: 
  DISPLAY Customer. 
END. 

r-cnct2.p
CONNECT sports2000 -1. 
RUN r-dispcu.p. 

This time, database sports2000 is connected before r-dispcu.p is invoked, so r-dispcu.p runs successfully.

Notes
See also

ALIAS function, CONNECTED function, CREATE ALIAS statement, CREATE CALL statement, DATASERVERS function, DBCODEPAGE function, DBCOLLATION function, DBRESTRICTIONS function, DBTYPE function, DBVERSION function, DELETE ALIAS statement, DISCONNECT statement, FRAME-DB function, LDBNAME function, NUM-DBS function, PDBNAME function, SDBNAME function


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex