Re: Connection string

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Harpreet Dhaliwal <harpreet(dot)dhaliwal01(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Connection string
Date: 2006-08-10 04:57:07
Message-ID: 20060810045707.GA75057@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Sidney-Woollett 2006-08-10 06:57:44 Re: Importance of re-index
Previous Message Steve Atkins 2006-08-10 04:08:30 Re: Accessing Database Data from C Function