Using CONNECT
Go Up to Declaring and Initializing Databases
The CONNECT
statement attaches to a database, opens the database, and allocates system resources for it. A database must be opened before its tables can be used. To include CONNECT
in a program, use the following syntax:
EXEC SQL CONNECT handle;
A separate statement can be used for each database, or a single statement can connect to multiple databases. For example, the following statements connect to two databases:
EXEC SQL CONNECT DB1; EXEC SQL CONNECT DB2;
The next example uses a single CONNECT
to establish both connections:
EXEC SQL CONNECT DB1, DB2;
Once a database is connected, its tables can be accessed in subsequent transactions. Its handle can qualify table names in SQL applications, but not in DSQL applications. For a complete discussion of CONNECT
options and using database handles, see Working with Databases.