Search Postgresql Archives

Re: Connection string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a simple code snippet that i've written to check if i can connect to the postgres database server residing at IP 192.168.0.123. DB name is xyz
Also, user account jsb has the access to the database xyz.
------------------------------------------------------------
#include <stdio.h>
 
EXEC SQL INCLUDE sqlca
 
int main ()
{
     EXEC SQL BEGIN DECLARE SECTION;
         char abc[20];
     EXEC SQL END DECLARE SECTION;
 
     EXEC SQL CONNECT TO  'tcp:postgresql://192.168.0.123/xyz' USER jsb
 
    printf("Error code is: %d ", SQLCODE);
 
 
}
 
---------------------------------------------------------------------------------------------------------------------------
 
The error code that it gives me is -402 that means it could not establish the connection.
 
Don't know whats going wrong.
 
Thanks,
Harpreet.
 

 
On 8/10/06, Michael Fuhr <mike@xxxxxxxx> wrote:
On Thu, Aug 10, 2006 at 12:02:24AM -0400, Harpreet Dhaliwal wrote:
> I already read that documentation.
>
> My ECPG code for connecting to the DB server is:
>
> EXEC SQL CONNECT TO 192.168.1.100:/xyz

That format isn't shown in the documentation; the ecpg preprocessor
should fail with a syntax error if you try using it.

> i also tried
>
> tcp:postgresql://192.168.1.100[:*port*][/*dbname*][?*options*]

The above is probably what you need, but without seeing the exact
code you tried it's hard to say why it's not working.

> unix:postgresql://*192.168.1.100*[:*port*][/*dbname*][?*options*]

The ecpg preprocessor shouldn't allow this -- it should fail with
an error like "unix domain sockets only work on 'localhost' but not
on '192.168.1.100'".

> but unfortunately it say DB doesn't exist.

Are you sure the database exists?  Can you connect to it with
psql?

> I don't know the right way to use IP addresses while connecting to a
> postgres DB using ECPG.

If you have a server on 192.168.1.100 listening on the default port
(5432, or whatever PGPORT is set to) and you want to connect to a
database named "mydb" on that server, then the following should
work:

EXEC SQL CONNECT TO tcp:postgresql://192.168.1.100/mydb;

If the database is listening on another port, say 12345, then
this should work:

EXEC SQL CONNECT TO tcp:postgresql://192.168.1.100:12345/mydb;

If you're getting 'database "mydb" does not exist' errors then try
connecting with psql and make sure the database really does exist.
If you still have trouble then please post a minimal but complete
program so we can see everything you're doing.

--
Michael Fuhr


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux