Re: PostgresSQL server connectiong problem with C-language...

From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Madhu Sudhana Rao" <madhu542(at)gmail(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PostgresSQL server connectiong problem with C-language...
Date: 2007-10-15 11:13:34
Message-ID: 36e682920710150413s2d9311a3u1d61997af6888998@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On 10/15/07, Madhu Sudhana Rao <madhu542(at)gmail(dot)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(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Adam Radlowski 2007-10-23 06:20:40 sending data with COPY SQL command, libpq and structure of SELECT resulting buffer
Previous Message Madhu Sudhana Rao 2007-10-15 06:13:04 PostgresSQL server connectiong problem with C-language...