Using Adaptive Server connections

Specify a connection name for any Embedded SQL statement that you want to execute on a connection other than the default unnamed connection. If your application program uses only one connection, you can leave the connection unnamed. Then, you do not need to use the at clause.

The syntax for using multiple connections is:

exec sql [at connection_name] sql_statement;

where sql_statement is a Transact-SQL statement.

The following example shows how two connections can be established to different servers and used in consecutive statements:

    ... 
 
 exec sql begin declare section; 
 CS_CHAR user[16]; 
 CS_CHAR passwd[16]; 
 CS_CHAR name; 
 CS_INT  value, test; 
 CS_CHAR server_1[BUFSIZ]; 
 CS_CHAR server_2[BUFSIZ]; 
 exec sql end declare section; 
 ... 
 strcpy (server_1, "sybase1"); 
 strcpy (server_2, "sybase2"); 
 strcpy(user, "my_id");
 strcpy(passwd, "mypass");
 
 exec sql connect :user identified by :passwd  
 at connection_2 using :server_2;
 
 exec sql connect :user identified by :passwd using
:server_1; 
 
 /* This statement uses the current "server_1"
 connection */ 
 exec sql select royalty into :value from authors
 where author = :name; 
 
 if (value == test) 
 { 
 /* This statement uses connection "connection_2" */ 
 exec sql at connection_2 update authors
 set column = :value*2  
 where author = :name; 
 }