Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

434
Views
How to query PostgreSQL from VBA

How can I query PostreSQL in VBA? I have tried the following which I found online but doesn't seem to work.

Sub query()

'Create Connection
Set conn = CreateObject("ADODB.Connection")
strCnx = "Driver={PostgreSQL UNICODE};Server=localhost;Database=databasename;uid=username;pwd=password123;"
conn.Open strCnx

'Query the Database
Set rs = CreateObject("ADODB.recordset")
rs.Open "select * from dm.acct_dim limit 10", conn

Record = rs.GetRows()
rs.Close
conn.Close

'Write results to file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\dbData.txt", 8, True)

For Each Item In Record
  objFile.WriteLine (Item)
Next

objFile.Close

End Sub

When I try this i get an error saying "could not connect to the server; No Connection could be made because the target machine actively refused it."

When I connect with pgadmin i use host, port, database, username and password. So I'm guessing i need those same things in the connection string but not exactly sure how that should be setup. I'm a rookie here. thanks for any help.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Looks like it was correct as it was. My problem was that I had wrong server. My bad. Thanks for trying to help!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!