Establishes a connection to the database identified by database-name running on the server identified by engine-name.
Syntax 1
CONNECT … [ TO engine-name ] …[ DATABASE database-name ] …[ AS connection-name ] …[ USER ] userid [ IDENTIFIED BY ]
Syntax 2
CONNECT USING connect-string
EXEC SQL CONNECT AS :conn_name USER :userid IDENTIFIED BY :password; EXEC SQL CONNECT USER "dba" IDENTIFIED BY "sql";
Connect to a database from dbisql. Prompts display for user ID and password:
CONNECT
Connect to the default database as DBA, from dbisql. A password prompt displays:
CONNECT USER "DBA"
Connect to the demo database as the DBA, from dbisql,where <machine>_iqdemo is the engine name:
CONNECT TO <machine>_iqdemo USER "DBA" IDENTIFIED BY sql
Connect to the demo database using a connect string, from dbisql:
CONNECT USING 'UID=DBA;PWD=sql;DBN=iqdemo'
The WHENEVER statement, SET SQLCA, and some DECLARE statements do not generate code and thus might appear before the CONNECT statement in the source file. Otherwise, no statements are allowed until a successful CONNECT statement has been executed.
The user ID and password are used for permission checks on all dynamic SQL statements. By default, the password is case-sensitive; the user ID is not. You can connect without a password by using a host variable for the password and setting the value of the host variable to be the null pointer.
CREATE TABLE t1( c1 int ); CONNECT DBA IDENTIFIED BY sql; CREATE TABLE t2 (c1 int );
No other database statements are allowed until a successful CONNECT statement has been executed.
The user ID and password are used for checking the permissions on SQL statements. If the password or the user ID and password are not specified, the user is prompted to type the missing information. By default, the password is case-sensitive; the user ID is not.
Multiple connections are managed through the concept of a current connection. After a successful connect statement, the new connection becomes the current one. To switch to a different connection, use SET CONNECTION. Executing a CONNECT statement does not close the existing connection (if any). Use DISCONNECT to drop connections.
Static SQL statements use the user ID and password specified with the -l option on the SQLPP statement line. If no -l option is given, then the user ID and password of the CONNECT statement are used for static SQL statements also.