Embedded SQL - Unable to connect to PostgreSQL Database

From: cvk_ind(at)rediffmail(dot)com (vicky)
To: "pgsql-general(at)postgresql(dot)org(dot)pgsql-hackers"(at)postgresql(dot)org
Subject: Embedded SQL - Unable to connect to PostgreSQL Database
Date: 2004-05-29 20:26:13
Message-ID: fd3fe14a.0405291226.5902a0a0@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Hello Experts,
Trying to run sample Postgrel's ECPG(Embedded
SQL)programs on RHL 9.0.

Im unable to connect to PostgreSQL database (sirishadb) when I run
the program ....

# su postgres (enter)

# /usr/bin/ecpg -t -I/usr/include/pgsql/sample1.pgc (enter)

# gcc -g -o sample1 -I /usr/include/pgsql sample1.c -lecpg -lpq
(enter)

# ./sample1(enter)

Error Code: -220
Message: No such connection NULL in line 12 ,
Rows : 0
Warning:
sql error No such connection Null in line 18

I did lot of 'googling' ,searched usenet groups and changed the
following ..............

*********************************************************************

In the source code (sample1.pcg) ........I tried out various
combinations of connect statements they are
---------------------------------------------------------------------

exec sql connect to 'sirishadb(at)localhost' /* where sirishadb is
databasename */

exec sql connect to 'sirishadb(at)lucky' /* where sirishadb is
databasename and lucky is hostname of the server */

exec sql connect to tcp:postgresql://localhost:5432/sirishadb as
connect_2 user postgresql using post123

In /var/lib/pgsql/data/postgresql.conf
----------------------------------------------------
tcpip_socket = true

In /var/lib/pgsql/data/pg_hba.conf
------------------------------------------------
local all all trust
host all all 127.0.0.1 255.255.255.255 trust
host all all xxx.xxx.xxx.0 255.255.255.0 trust

In /etc/rc.d/init.d/postgresql
--------------------------------------
In this file I added -i to the following statement

su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl -D $PGDATA -p
/usr/bin/postmaster -o '-p ${PGPORT} -i' start > /dev/null 2>&1" <
/dev/null

*********************************************************************

Plz help me in connecting to the database .........Thanx in advance

Regards,
Vikram

Source code of sample1.pcg
---------------------------
#include <stdlib.h>
#include <stdio.h>

exec sql include sqlca;

main() {

exec sql connect to 'sirishadb(at)localhost';

/*exec sql connect to tcp:postgresql://localhost:5432/sirishadb as
connect_2 user postgresql using post123; */

exec sql BEGIN WORK;

exec sql UPDATE XXchildren SET fname = 'Emma' WHERE age = 0;

printf("error code %d, message %s, rows %d, warning %c\n",
sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc, sqlca.sqlerrd[2],
sqlca.sqlwarn[0]);

exec sql COMMIT WORK;

exec sql disconnect all;

return EXIT_SUCCESS;

}

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2004-05-29 22:10:42 Re: Use arrays to store multilanguage texts
Previous Message Joe Conway 2004-05-29 15:30:56 Re: Use arrays to store multilanguage texts

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2004-05-29 21:38:08 Re: Extended customizing, SQL functions,
Previous Message Andrew Dunstan 2004-05-29 19:37:51 Re: dynamic_library_path on Win32