Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id E4B279F9D90 for ; Mon, 15 Oct 2007 03:14:26 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 54342-01-4 for ; Mon, 15 Oct 2007 03:13:33 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.179]) by postgresql.org (Postfix) with ESMTP id 3A5AB9FA340 for ; Mon, 15 Oct 2007 03:13:10 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id m38so2160616waf for ; Sun, 14 Oct 2007 23:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=sWsB8aVysKO5BEdUUclQKT2xBYzNJK3UzK0r8kMdiIo=; b=Gr0+VFfhbcRzXpAv0x1VGdTBw9LMiuGDSaixA2tJmbjnf2kQfvZXWZ+5A7fjz84FBXh7hCMMGIYrgnajfKcTV/K3Fvli4oX7yCpkQXchuaR1mqLjxWKKGI1XbtjSjfKxBo8jYDNbY1pphobP+7sp0Jq2ZnlSi6tYXqu7xF1M1mc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=HncybqyxNp56FzGZFAEtZEQ6TFQevRodZ4Dk9U+1nkv6ER/HwZSDta/n3h2SCEobhQX1Xw+6mTapcqIGipbDnDdY+NGf9QYL9lNnk2uVbr3hlOY+PRbF6w72+9BpId6ONZoJB/Nyle73LCmTnA3GiChdwRRFeEcw8P5JEPesh0M= Received: by 10.114.120.1 with SMTP id s1mr6568458wac.1192428784391; Sun, 14 Oct 2007 23:13:04 -0700 (PDT) Received: by 10.114.120.18 with HTTP; Sun, 14 Oct 2007 23:13:04 -0700 (PDT) Message-ID: Date: Mon, 15 Oct 2007 11:43:04 +0530 From: "Madhu Sudhana Rao" To: pgsql-interfaces@postgresql.org Subject: PostgresSQL server connectiong problem with C-language... MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/7 X-Sequence-Number: 6634 Hi, I wrote a C-program for connecting to postgresSQL server and get the data from the database. The program is as fallows:- Code: ( c ) #include #include #include "libpq-fe.h" /* libpq header file */ int main() { char state_code[3]; char query_string[256]; /* holds constructed SQL query */ PGconn *conn; /* holds database connection */ PGresult *res; int i; conn = PQconnectdb("dbname=test"); /* connect to the database */ if (PQstatus(conn) == CONNECTION_BAD) /* did the database connection fail? */ { fprintf(stderr, "Connection to database failed.\n"); fprintf(stderr, "%s", PQerrorMessage(conn)); exit(1); } printf("Enter a state code: "); /* prompt user for a state code */ scanf("%2s", state_code); sprintf(query_string, /* create an SQL query string */ "SELECT name \ FROM statename \ WHERE code = '%s'", state_code); res = PQexec(conn, query_string); /* send the query */ if (PQresultStatus(res) != PGRES_TUPLES_OK) /* did the query fail? */ { fprintf(stderr, "SELECT query failed.\n"); PQclear(res); PQfinish(conn); exit(1); } for (i = 0; i < PQntuples(res); i++) /* loop through all rows returned */ printf("%s\n", PQgetvalue(res, i, 0)); /* print the value returned */ PQclear(res); /* free result */ PQfinish(conn); /* disconnect from the database */ return 0; } I changed the postgresql.conf and pg_hba.conf files. listen_addresses = '*' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost', '*' = all # (change requires restart) port = 5432 # (change requires restart) max_connections = 100 ---------------------------------------------------------------------------- # TYPE DATABASE USER CIDR-ADDRESS METHOD local all all trust # The same using local loopback TCP/IP connections. # # TYPE DATABASE USER CIDR-ADDRESS METHOD host all all 0.0.0.0/0 trust every time I a getting the same error when I was trying to run the program:- 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"? Thanks for reading this long mail. could any one plz help me how to solve this problem... Thanks & Regards... Madhu.