如何将PostgreSQL与VB.NET应用程序连接起来

时间:2014-01-15 14:18:25

标签: vb.net postgresql database-connection pgadmin

我想用PostgreSQL 9.3连接我的VB.NET windows应用程序 Beibg是一个初学者我无法通过ODBC和Npgsql

来做到这一点
Dim mDAKap As New Odbc.OdbcDataAdapter
Dim mCon As New Odbc.OdbcConnection
mCon.ConnectionString = "Dsn=PostgreSQL30;database=public;server=127.0.0.1;port=5432;uid=root;pwd=root"
mCon.Open()

我在mCon.OPen()

上收到错误

请帮助我的参数是否正确?

1 个答案:

答案 0 :(得分:7)

从另一个来源获得我的回答,为我这样的其他初学者写作,以节省他们的时间:

首先安装ODBC驱动程序(在此处获取http://www.postgresql.org/ftp/odbc/versions/msi/) 安装32位驱动程序::

Dim MyCon As New Odbc.OdbcConnection
MyCon.ConnectionString = "Driver={PostgreSQL ANSI};database=database_name;server=127.0.0.1;port=5432;uid=postgres;sslmode=disable;readonly=0;protocol=7.4;User ID=postgres;password=password;"

MyCon.Open()
        If mCon.State = ConnectionState.Open Then
            MsgBox("Connected To PostGres", MsgBoxStyle.MsgBoxSetForeground)
        End If