Improve company productivity with a Business Account.Sign Up

x
?
Solved

How to Connect Postgres from Visual Basic???

Posted on 2001-09-13
6
Medium Priority
?
1,183 Views
Last Modified: 2008-02-01
How to Connect Postgres from Visual Basic??? is it possible?? if yes, how??

Provide me with exact solution...

actually postgres is on linux server and vb is on NT client..

thanks in advance

Hari.
0
Comment
Question by:sharibabu
6 Comments
 
LVL 32

Accepted Solution

by:
Brendt Hess earned 200 total points
ID: 6480185
There is an ODBC driver for PostgreSQL that can be used.  Check http://odbc.postgresql.org for downloads, FAQ, etc.  You can retrieve the driver from ftp://ftp.postgresql.org/pub/odbc

Once you install the ODBC driver and set up your DSNs, you would connect to the Postgresql DB just like any other DB using ODBC (extensive documentation and examples come with VB for this).

You could even use the ODBC to ADO bridge driver from MS to use ADO connections / recordsets if you prefer ADO.

There is an ODBC FAQ at http://www.ca.postgresql.org/ftpsite/odbc/faq.html

Here is some example code for an ADO connection to an IP location server:

Private Sub Connection_Test()

Dim adcon1 As New ADODB.Connection
Dim adcmd1 As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim AccessConnect As String

AccessConnect =
"driver={PostgreSQL};server=192.168.1.59;database=testdata;uid=IAmAUser;pwd=;"
adcon1.ConnectionString = AccessConnect
adcon1.Open

adcmd1.ActiveConnection = conn1
adcmd1.CommandText = "Select * from MyTable order by MyField"
Set rs = adcmd1.Execute

Do While Not rs.EOF
    Debug.Print rs("MyField"),  rs("MyOtherField")
    rs.MoveNext
Loop

rs.close
adcmd1.close
adcon1.close

End Sub

0
 

Author Comment

by:sharibabu
ID: 6484318
hi bhess1

Thanks for ur solution again...
now iam connecting the postgres from my NT client... i have installed postgres odbc driver on my NT client and executed the project successfully

i have one doubt...

i have made setup of the project and installed on the other NT client(which doesn't contain the postgres odbc driver) but is not executing and giving following runtime error

Run-time error '-2147467259(80004005)':
[Microsoft][ODBC Driver Manager] Data source name not found and no default dirver specified

After that i have installed postgres odbc driver and executed.. even then it is not executing...

should i add any dll's while making the setup??

give the exact solution and also, steps for making a setup.

Thank U...
0
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 6488092
Have you tried connecting to the other server via the ODBC manager?  Try, and post any error messages returned...

Possible problems:

uid / password problems - are you accepting the default, or do you specify uid/pwd?

Permissions problems - does the user on the new machine have any permissions needed?

Can you show your connection string? (post here)

Check this checklist - this should be what you need to make a connection:

--- ODBC Driver Data Source Checks ---
Valid and resolvable hostname.
Valid port number.  (default is 5432)
Valid and existing database name.
Valid user name.
Valid password for the specified user.  (Required if pg_hba.config is set to password authenticate your client.)


0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
LVL 54

Expert Comment

by:nico5038
ID: 7262000

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - Answered by: bhess1
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 

Expert Comment

by:Jgould
ID: 7292713
Question has been closed as per recommendation

JGould-EE Moderator
0
 

Expert Comment

by:caco00
ID: 8719249
Watch out for the driver name

When you install the ODBC from PostgreSQL the driver name is set for default to PostgreSQL(version name)

In your first code you say that the driver name is {PostgreSQL}
0

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

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

In this article, we will show how to detach and attach a database and then show how to repair a corrupt database and attach it, If it has some errors. We will show how to detach and attach using SSMS or using T-SQL sentences.
I recently worked on a Wordpress site that utilized the popular ContactForm7 (https://contactform7.com/) plug-in that only sends an email and does not save data. The client wanted the data saved to a custom CRM database. This is my solution.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question