Re: PostgresSQL server connectiong problem with C-language... - Mailing list pgsql-interfaces

From Jonah H. Harris
Subject Re: PostgresSQL server connectiong problem with C-language...
Date
Msg-id 36e682920710150413s2d9311a3u1d61997af6888998@mail.gmail.com
Whole thread Raw
In response to PostgresSQL server connectiong problem with C-language...  ("Madhu Sudhana Rao" <madhu542@gmail.com>)
List pgsql-interfaces
On 10/15/07, Madhu Sudhana Rao <madhu542@gmail.com> wrote:
> I wrote a C-program for connecting to postgresSQL server and get the
> data from the database.
> ...
> Connection to database failed.
> could not connect to server: No such file or directory
> Is the server running locally and accepting
> connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Is the server running?  Does the log show anything unusual?  Did you
change any of the unix_socket_* configuration parameters?  Do you have
a database named test (although that would give a different error
message).  Can you connect with psql?

As far as libpq is concerned, the best thing to do is start with is
the libpq example code and work from there.

Also, sorry to be picky about your code, but your conditional is:

if (PQstatus(conn) == CONNECTION_BAD)

It's generally better to make the conditional check for an alteration
to the expected result:

if (PQstatus(conn) != CONNECTION_OK)

It just makes it easier to understand what should've happened.

-- 
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation                | fax: 732.331.1301
499 Thornall Street, 2nd Floor          | jonah.harris@enterprisedb.com
Edison, NJ 08837                        | http://www.enterprisedb.com/


pgsql-interfaces by date:

Previous
From: "Madhu Sudhana Rao"
Date:
Subject: PostgresSQL server connectiong problem with C-language...
Next
From: Adam Radlowski
Date:
Subject: sending data with COPY SQL command, libpq and structure of SELECT resulting buffer