Creates a connection to Adaptive Server.
exec sql connect user_name [identified by password] [at connection_name] [using server_name] [labelname label_name labelvalue label_value …] end-exec
The user name to be used when logging into Adaptive Server.
The password to use to log in to Adaptive Server.
A name that you choose to uniquely identify the Adaptive Server connection.
The server name of the Adaptive Server to which you are connecting.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 UID PIC X(32).
01 PASS PIC X(32).
01 SERVER PIC X(100).
EXEC SQL END DECLARE SECTION END-EXEC.
DISPLAY "UID NAME?".
ACCEPT UID.
DISPLAY "PASSWORD ?".
ACCEPT PASS.
DISPLAY "SERVER TO CONNECT TO ?".
ACCEPT SERVER.
EXEC SQL CONNECT :UID IDENTIFIED BY :PASS
USING :SERVER END-EXEC.
In every Embedded SQL program, the connect statement must be executed before any other executable SQL statement except allocate descriptor.
The label_name and label_value clauses, if used, must be the last clauses of the connect statement.
If a program uses both C and COBOL languages, the first connect statement must be issued from a COBOL program.
If a program has multiple connections, only one can be unnamed.
If an Embedded SQL statement does not have an at connection_name clause to direct it to a specific named connection, the statement is executed on the current connection.
To specify a null password, omit the identified by clause or use an empty string.
If the connect statement does not specify an Adaptive Server, the server named by the DSQUERY environment variable or logical name is used. If DSQUERY is not defined, the default server is SYBASE.
Client-Library looks up the server name in the interfaces file located in the directory specified by the SYBASE environment variable or logical name.
The Adaptive Server connection ends when the Embedded SQL program exits or issues a disconnect statement.
Opening a new connection, named or unnamed, results in the new connection becoming the current connection.
A program that requires multiple Adaptive Server login names can have a connection for each login account.
By connecting to more than one server, a program can simultaneously access data stored on different servers.
A single program can have multiple connections to a single server or multiple connections to different servers.
The following table shows how a connection is named:
If this clause is used |
But without |
Then, the ConnectionName is |
---|---|---|
at connection_name |
connection_name |
|
using server_name |
at |
server_name |
None |
DEFAULT |
at connection_name, exec sql, disconnect, set connection