Previous Topic

Next Topic

Connection to a Remote Database

A connection to a database can be made either in the local mode or in the remote mode. At most one connection could be in the local mode. For example, to connect to the custdb database in the local mode and associate this connection with a connection name conn_1, the statement would be:

EXEC SQL
 CONNECT TO '6597@localhost:custdb' as 'conn_1' ;

Here the string “6597@localhost:custdb” is referred to as the connect string. The connect string specifies the port, the target host for the database, and the database name.

To connect to a database in the remote mode, the statement would be:

EXEC SQL
CONNECT TO '6597@remotehost:salesdb' as 'conn_2' ;

Here “6597@remotehost:salesdb” is the connect string that has the database name, salesdb, to be connected to and conn_2 is the connection name associated with this connection. remotehost is the name of the remote machine having the database salesdb.