Database Reference
In-Depth Information
Disconnecting using ECPG
The SQL DISCONNECT command is used to disconnect from the server. This command
can disconnect from current, default, and all sessions. Its syntax is as follows:
EXEC SQL DISCONNECT [connection];
Here connection is the name of the connection to disconnect. It can be the
connection name, DEFAULT , CURRENT , or ALL .
Selecting a connection
We have already discussed that we can create multiple connections with the
database in ECPG. There is a way to select connections too. ECPG provides multiple
ways to select the connection.
One way is to switch between the connections using the connection name. In this
case, the connection is switched and all the SQL commands will use that connection.
The syntax of the SET CONNECTION statement is as follows:
EXEC SQL SET CONNECTION connection-name;
Here connection-name is the name of the connection, as we provided while
connecting with PostgreSQL.
The other way is to explicitly select a connection for each and every SQL command
as follows:
EXEC SQL AT connection-name SQL command;
Here is an example of a pgc program to establish multiple connections with
PostgreSQL using ECPG. The following code used Unix domain sockets and
a TCP variant to connect to PostgreSQL:
/*----------------------------------------------------------------
*
*connection.pgc
*Connecting PostgreSQL Server using ecpg
*
*IDENTIFICATION
*connection.pgc
*
*----------------------------------------------------------------
*/
#include<stdio.h>
 
Search WWH ::




Custom Search