LupusX Posted February 12, 2008 Share Posted February 12, 2008 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 More sharing options...
ptrex Posted February 12, 2008 Share Posted February 12, 2008 @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 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
LupusX Posted February 12, 2008 Author Share Posted February 12, 2008 ... 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 More sharing options...
DataMiner Posted September 19, 2008 Share Posted September 19, 2008 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/631251Then 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now