Cannot login, with C/C++ program

Started by Danielover 16 years ago5 messagesgeneral
Jump to latest
#1Daniel
danwgrace@gmail.com

I have written a C/C++ program that trys to log into a local
PostgreSQL database. Here is the code:

pg_conn = PQconnectdb(
"hostaddr = '127.0.0.1' port = '' dbname = 'TBDB' user = 'sysdba'
password = 'stelmo777' connect_timeout = '10'");
if (!pg_conn)
{
return false;
}
if (PQstatus(pg_conn) != CONNECTION_OK)
{
return false; // <- execution reaches here.

I checked the database, user and password by logging in with psql.
What could be wrong?

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Daniel (#1)
Re: Cannot login, with C/C++ program

Daniel <danwgrace@gmail.com> writes:

I have written a C/C++ program that trys to log into a local
PostgreSQL database. Here is the code:

pg_conn = PQconnectdb(
"hostaddr = '127.0.0.1' port = '' dbname = 'TBDB' user = 'sysdba'
password = 'stelmo777' connect_timeout = '10'");
if (!pg_conn)
{
return false;
}
if (PQstatus(pg_conn) != CONNECTION_OK)
{
return false; // <- execution reaches here.

I checked the database, user and password by logging in with psql.
What could be wrong?

If you print out the connection object's error message, you might
find out. It's hard to guess about it without that information.

regards, tom lane

#3Pedro Doria Meunier
pdoria@netmadeira.com
In reply to: Tom Lane (#2)
Re: Cannot login, with C/C++ program

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Did you check you pg_hba.conf ?
another thing: although port defaults to 5432 you *should* specify
that in the connection string.
also... is "sysdba" *really* an authorized user? check your permissions...

BR,
Pedro.

On 12/02/2009 09:42 PM, Tom Lane wrote:

Daniel <danwgrace@gmail.com> writes:

I have written a C/C++ program that trys to log into a local
PostgreSQL database. Here is the code:

pg_conn = PQconnectdb(
"hostaddr = '127.0.0.1' port = '' dbname = 'TBDB' user = 'sysdba'
password = 'stelmo777' connect_timeout = '10'");
if (!pg_conn)
{
return false;
}
if (PQstatus(pg_conn) != CONNECTION_OK)
{
return false; // <- execution reaches here.

I checked the database, user and password by logging in with psql.
What could be wrong?

If you print out the connection object's error message, you might
find out. It's hard to guess about it without that information.

regards, tom lane

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAksW6nMACgkQ2FH5GXCfxAuOBgCeMdssoz+fE26lFX9StTCksUyp
tAkAoKKbnjPrE4fk8HpEbLYJHq3wq7UB
=e3vc
-----END PGP SIGNATURE-----

#4Daniel Verite
daniel@manitou-mail.org
In reply to: Daniel (#1)
Re: Cannot login, with C/C++ program

Daniel wrote:

I have written a C/C++ program that trys to log into a local
PostgreSQL database. Here is the code:

pg_conn = PQconnectdb(
"hostaddr = '127.0.0.1' port = '' dbname = 'TBDB' user = 'sysdba'
password = 'stelmo777' connect_timeout = '10'");
if (!pg_conn)
{
return false;
}

In the program, you should
fprintf(stderr, "%s", PQerrorMessage(pg_conn))
and/or
copy-paste for us the psql command line that works.

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org

#5Daniel
danwgrace@gmail.com
In reply to: Daniel (#1)
Re: Cannot login, with C/C++ program

Oops, as it happens I had an error in my program logic and pg_conn was
actually true.