Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

436
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda