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 …];
The user name to be used when logging in to 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;
CS_CHAR user[32];
CS_CHAR password[32];
CS_CHAR server[90];
CS_CHAR conname[20];
exec sql end declare section;
strcpy(user, “mylogin”);
strcpy(password, “mypass”);
strcpy(server, “YOURSERVER”);
strcpy(conname, “con_one”);
exec sql connect :user identified by :password
using :server at :conname;
In every Embedded SQL program, the connect statement must be executed before any other executable SQL statement except allocate descriptor.
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, and will be the default connection.
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 a 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 Connection Name is |
---|---|---|
at connection_name |
connection_name |
|
using server_name |
at |
server_name |
None |
DEFAULT |
at connection_name, exec sql, disconnect, set connection