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

"Jonah H. Harris" <[email protected]>
Newsgroups gmane.comp.db.postgresql.interfaces
Message-ID <[email protected]>
On 10/15/07, Madhu Sudhana Rao <[email protected]> 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          | [email protected]
Edison, NJ 08837                        | http://www.enterprisedb.com/

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.