Jump to content

Postgres SQL Connection


LupusX
 Share

Recommended Posts

Hello,

I'm trying to connect to Postgres SQL Database on remote Server.

I'm doing it like that:

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Mode = 16 ; shared
$sqlCon.CursorLocation = 3; client side cursor
$sqlCon.Open ("Driver={PostgreSQL ANSI}; IP=10.220.2.4; Port=5432; Database=baza; UID=user; PWD=pass")

But i have error:

wplaty.au3 (74) : ==> The requested action with this object has failed.: 
$sqlCon.Open ("Driver={PostgreSQL ANSI}; IP=10.xxx.yyy.zzz; Port=5432; Database=baza; UID=user; PWD=pass") 
$sqlCon.Open ("Driver={PostgreSQL ANSI}; IP=10.xxx.yyy.zzz; Port=5432; DDatabase=baza; UID=user; PWD=pass")^ ERROR

I also tried to do this like that:

$oConn = ObjCreate("ADODB.Connection")
$line2 = "DRIVER={PostgreSQL ANSI};DATABASE=baza;" & _
            "SERVER=10.xxx.yyy.zzz;PORT=5432;Uid=user;" & _
            "Pwd=pass;" & _
            "A0=0;A1=6.4;A2=0;A3=0;A4=0;A5=0;A6=;A7=100;A8=4096;A9=0;" & _
            "B0=254;B1=8190;B2=0;B3=0;B4=1;B5=1;B6=0;B7=1;B8=0;B9=1;C0=0;C1=0;C2=dd_"

$oConn.Open ($line2)
$oConn.execute ($query)
$oConn.Close

But I received the same error code.

What I was doing wrong?

Link to comment
Share on other sites

@LupusX

I don't have a Postgress to test with but try to add more quotes in the connections string like this.

Func postgres_query($query)
$oConn = ObjCreate("ADODB.Connection")
$oRS = ObjCreate("ADODB.Recordset")
$cmd = ObjCreate("ADODB.Command")

$line2 =     "DRIVER={PostgreSQL ANSI};DATABASE='Incoming_rates';" & _
            "SERVER='localhost';PORT=5432;Uid='odbc_usr';" & _
            "Pwd='odbc_usr';" & _ 
            "A0=0;A1=6.4;A2=0;A3=0;A4=0;A5=0;A6=;A7=100;A8=4096;A9=0;" & _
            "B0=254;B1=8190;B2=0;B3=0;B4=1;B5=1;B6=0;B7=1;B8=0;B9=1;C0=0;C1=0;C2=dd_"

$oConn.Open ($line2)
$oConn.execute ($query)
$oConn.Close

EndFunc

; Or try this

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Mode = 16 ; shared
$sqlCon.CursorLocation = 3; client side cursor
$sqlCon.Open ("Driver={PostgreSQL ANSI};IP=10.220.2.4;Port=5432;Database='baza';UID='user';PWD='pass'")

regards,

ptrex

Link to comment
Share on other sites

... Still the same problem...

@LupusX

I don't have a Postgress to test with but try to add more quotes in the connections string like this.

Func postgres_query($query)
$oConn = ObjCreate("ADODB.Connection")
$oRS = ObjCreate("ADODB.Recordset")
$cmd = ObjCreate("ADODB.Command")

$line2 =     "DRIVER={PostgreSQL ANSI};DATABASE='Incoming_rates';" & _
            "SERVER='localhost';PORT=5432;Uid='odbc_usr';" & _
            "Pwd='odbc_usr';" & _ 
            "A0=0;A1=6.4;A2=0;A3=0;A4=0;A5=0;A6=;A7=100;A8=4096;A9=0;" & _
            "B0=254;B1=8190;B2=0;B3=0;B4=1;B5=1;B6=0;B7=1;B8=0;B9=1;C0=0;C1=0;C2=dd_"

$oConn.Open ($line2)
$oConn.execute ($query)
$oConn.Close

EndFunc

; Or try this

$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Mode = 16 ; shared
$sqlCon.CursorLocation = 3; client side cursor
$sqlCon.Open ("Driver={PostgreSQL ANSI};IP=10.220.2.4;Port=5432;Database='baza';UID='user';PWD='pass'")

regards,

ptrex

.. any ideas ?

regards

Link to comment
Share on other sites

  • 7 months later...

I had this same issue, and spent some time searching the forum and google....come to find out it wasn't the ADODB.Connection or my code.

If you're trying to connect to postgreSQL from Windows, you need to make sure your DSN in setup properly. Control Panel -> Administrative Tools -> Data Sources(ODBC). If you don't see a User DSN called PostgreSQL, this is likely part of the issue. Details on setting this up here: http://www.developer.com/open/article.php/631251

Then you need to use the DSN properly with the driver parameter in your code. So I setup the Postgre ANSI DSN and here is the code:

$oConn = ObjCreate("ADODB.Connection")
    $line2 = "DRIVER={PostgreSQL ANSI};Server=localhost;Port=5432;Database=test;Uid=postgres;Pwd=test;"
    $oConn.Open ($line2)

Your driver parameter would be 'PostgreSQL UNICODE' if that's the DSN and database setup you've chosen.

Also, if you're not connecting to localhost, make sure your server is accepting external connections. Checking this with pgadmin is simple.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...