Jump to content
Sign in to follow this  
cag8f

Can't connect to postgresql db

Recommended Posts

cag8f

Hi all.  I'm trying to connect to a postgresql db with the code:

Local $oConn = ObjCreate("ADODB.Connection","localhost","postgres_username","postgres_password")
 
This fails and gives me an @error of -2147024770.  Any ideas on resolving or troubleshooting would be appreciated.
 
Here are some details that may or may not be relevant:
 
--system is running Windows 7 32 bit
--postgresql (version 8.3) is installed and a valid, working database has been created.
--I'm sure the username and password are correct because I can use them in PGAdmin to connect to the postgresql server and database.  I can successfully query, browse, and edit the database with PGAdmin when it connects using these credentials.
--I had read that there should be a postgresql entry in the User DSN tab located at Control Panel-->Administrative Tools-->Data Sources (ODBC).  There was not.  I added one manually, but the error persists.
--Using the OLE/COM Object Viewer, I can locate the ADODB.Connection object.  However, when I try to instantiate it, I receive the error:
 
CoGetClassObjectFailed
Class not registered
REGDB_E_CLASSNOTREG ($80040154)
 
I *can* instantiate the surrounding, related objects (e.g. ADODB.Command and ADODB.Record).  Furthermore, the ADODB.Connection object contains a couple more additional entries in the registry tab.
--Yesterday I *was* able to instantiate the ADODB.Connection object.  But then I installed the latest ODBC driver, and I believe that's when these problems began.
 
Thanks in advance.

Share this post


Link to post
Share on other sites
jchd

You would have a better chance asking on a postgres forum. You can also try creating the connection thru the DSN by using "DSN=yourDSNname" in the connection string.

When I had to connect to a non-SQLite database (or rather an ADO-supported engine), I always used that:

Func _AdoSQL_Connect($connectionString)

    $AdoSQLErr = ""
    Local $oAdoCon = ObjCreate("ADODB.Connection")
    If IsObj($oAdoCon) Then
        $_AdoSQL_LastConnection = $oAdoCon
        $oAdoCon.Open($connectionString) ;<==Connect with required credentials
        If Not @error Then
            Return SetError($AdoSQL_OK, 0, $oAdoCon)
        Else
            $AdoSQLErr = "Connection error"
        EndIf
    Else
        $AdoSQLErr = "Failed to create ADODB.Connection object"
    EndIf
    Return SetError($AdoSQL_FAIL, 0, $AdoSQL_FAIL)

EndFunc   ;==>_AdoSQL_Connect

This is my UDF which is a rewrite of ChrisL ADO UDF, which mimics the interface used in SQLite.au3.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
cag8f

Thanks.  I forgot to mention that I can successfully make this connection on a second computer.  The second computer has the same database loaded locally, and the connection is made without error (i.e. 2 separate systems, 2 separate postgresql servers, 2 separate postgresql databases).  The ADODB.Connection entries are a little different on each machine.  The registry entry on the problem computer contains an extra line beginning with "AppID."  I'm hoping the cause of that entry is the also the cause of my connection issue. I posted a related question in a couple Microsoft forums to hopefully learn more about the OLE/COM Object Viewer and track down this issue.

Share this post


Link to post
Share on other sites
jchd

I see. All I can do now is whish you best of luck!


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
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
Sign in to follow this  

×