If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Embedded SQL - Unable to connect to PostgreSQL Database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-31-04, 11:41
vikram_cvk vikram_cvk is offline
Registered User
 
Join Date: May 2004
Posts: 5
Question Embedded SQL - Unable to connect to PostgreSQL Database

lo 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@localhost' /* where sirishadb is
databasename */

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

exec sql connect to tcpostgresql://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@localhost';

/*exec sql connect to tcpostgresql://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;

}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On