I am trying to run a query from an Microsoft excel application and have not been able to connect successfully. I have PostgreSQL 9.3 on my local machine, and am running 64 bit windows 7. I have a sample database name dvdrental which is a demo database. I simply need to connect to the database, run a query, and view the output in my worksheet(or immediate window, either one resolves the connection issue). Here is what I have so far which is not working.
Option Explicit
Public objConnection As ADODB.Connection
Public strConnection As String
Public Sub TestPostgresConnection()
Dim strConnection As String
strConnection = "Driver={PostgreSQL Unicode};Server=localhost;Port=5432; Database=dvdrental;UID=sa;PWD=wrox;"
Set objConnection = New ADODB.Connection
Set objRecordSet = New ADODB.Recordset
objConnection.Open strConnection
With objRecordSet
.ActiveConnection = objConnection
.Open "SELECT * FROM actor"
End With
Do While Not objRecordSet.EOF
Debug.Print objRecordSet.Fields(0).Value
objRecordSet.MoveNext
Loop
objRecordSet.Close
objConnection.Close
Set objRecordSet = Nothing
Set objConnection = Nothing
End Sub
Here is a list of my references;
Visual Basic For Applications Microsoft Excel 14.0 Object Library OLE Automation Microsoft Office 14.0 Object Library Microsoft Forms 2.0 Object Library Microsoft Access 14.0 Object Library Microsoft ADO Ext. 6.0 for DOL and Security Microsoft ActiveX Data Objects 2.8 Library Microsoft Windows Common Confrols 6.0 (SP6)
When I execute this test method TestPostgresConnection, I get "[Miscrosoft][ODBC Driver Manager] Data source name not found and no default driver specified"
My setup of postgres has been standard and I have simply followed the directions on their website for creating a local RDBMS for testing.
Can anyone tell me why I am not able to connect and run a query? None of the solutions have worked so far. Thanks.