Embedded SQL in C connection issue

352 Views Asked by At

The Postgresql role is the owner of the db 'university' and it's been configured like,

alter user canoe password 'mypassword';

The piece of embedded SQL code in C just makes a connection to DB.

printf("SQLSTATE=[%s]\n", SQLSTATE);
EXEC SQL CONNECT TO 'university' USER 'canoe/mypassword'
printf("SQLSTATE=[%s]\n", SQLSTATE);

The code is compiled and linked. It's run on the localhost on which the postgresql server is running and listening on its default port.

$ ecpg connection.pgc
$ gcc -I/usr/include/postgresql connection.c -o conn -lecpg

The output of the compiled code is:

SQLSTATE=[00000]
SQLSTATE=[08001]

The error code 08001 means "sqlclient_unable_to_establish_sqlconnection". I've changed the configuration of postgresql to log all connection attempts in order to debug the code.

LOG: parameter "log_connections" changed to "on"
LOG: 00000: parameter "log_error_verbosity" changed to "verbose"

However, when the compiled code is run, there is no any error. When I connect it with pgsql, it has log info.

$ pqsql university -W
LOG: connection authorized: user=canoe database=university

The wired thing that I notice is even I enter wrong password after prompt, I can still get authorized. But my piece of C code doesn't work.

I can't resolve the issue or have any idea to debug it further. Any idea to where is the issue?

0

There are 0 best solutions below