Thread: Connecting to Postgres using Windows 7

Connecting to Postgres using Windows 7

From
Geoffrey Becker
Date:
I'm relatively new to postgres.  I've got a Visual Basic (VB)
application that i would like to connect to a Postgres database using
ODBC .  Both the VB application and postgres are on my laptop and both
work beautifully independent of each other.  Trouble is, I have a
windows 7 64bit OS and therefore I have been unable to get VB to connect
to the database.  My code is as follows:

     Public Class Form1

         Dim cCon As ADODB.Connection

         Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click

             On Error GoTo EH

             cCon.ConnectionString =
"DSN=MyDatabase;uid=MyUserID;pwd=MyPassword"

             cCon.Open()
             MsgBox("O.K.", vbInformation, "Connection Message")
             Exit Sub
     EH:
             MsgBox(Err.Description, vbCritical, "Error Message")
         End Sub

         Private Sub Form1_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
             cCon = New ADODB.Connection
         End Sub
     End Class

When I try to connect, all I get is a "Server does not exist or access
is denied" error.  I've tried configuring ODBC using odbcad32.exe as it
seems that is necessary on a 64 bit OS, but I'm not sure if that even
the right way to go.

Any help i could get would be much appreciated.

Thanks,

Geoff

Re: Connecting to Postgres using Windows 7

From
Craig Ringer
Date:
On 05/25/2011 09:49 PM, Geoffrey Becker wrote:

> When I try to connect, all I get is a "Server does not exist or access
> is denied" error. I've tried configuring ODBC using odbcad32.exe as it
> seems that is necessary on a 64 bit OS, but I'm not sure if that even
> the right way to go.

*which* odbcad32.exe?

Due to a nasty historical quirk Microsoft is stuck with for backward
compat, there are both 64-bit and 32-bit versions of odbcad32.exe .

http://support.microsoft.com/kb/942976

http://robertoschiabel.wordpress.com/2008/02/28/windows-x64-32bit-odbc-vs-64bit-odbc/

(Is this in the PgODBC documentation? It should be.)

--
Craig Ringer