• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 660
  • Last Modified:

Connection to a Postgres Database with visual Basic

Hello experts,

  I am wondering if anyone has a complete example code of how to connect to a Postgres database which is on a remote server in Visual Basic.  I am not a visual basic programmer (at all) but one of our programmers is.  However, he does not know how to connect to a database.    I am assuming he will need instructions on how to create an appropriate DSN in ODBC  if that is how VB'ers connect.

5 Solutions
Look Here:


(PostgreSQL is there)
gmanpertAuthor Commented:
Hey that's great, but it looks as if it only covers how to build a connection string.  What I am looking for is a simple program which connects, retrieves some data, prints it, then disconnects.   If this were Perl I could send you such a beast in a few seconds.   There must be at least one VB coder out there who has done something like this before.


This site is the ODBC driver that you will need to connect to the database. Once that is installed, just add a adobc connection to your form and use that driver to connect to the database.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

That connection string posted is for use in the ADO programming library.

Once you have successfully created an ADO connection, there are zillions of examples on the web of how to do data manipulation in ADO.

To be totally honest if your VB programmer doesn't know how to connect to a database I'd be a little worried.
    The connection string is as follows:
declare one variable strConnect, and write this in a procedure which is capable of taking the inputs like server, username, database, password which are used to prepare the connection to the postgre sql database.
create one variable of type connection string and assign the follwoing to that connection string variable. Then you made it.

      strConnect = "Driver={PostgreSQL};Server=" & strServer & _
                   ";port=5432;Database=" & strDatabase & _
                   ";Uid=" & strUserID & _
                   ";Pwd=" & strPassword
    'strConnect = "PayrollDSN"
    ' connection properties
    With m_connData
        .ConnectionString = strConnect
        .ConnectionTimeout = 30
        .CursorLocation = adUseClient
    End With

  I forgot one thing.  pls mention the ip-address of the system where your database is there.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now