繁体   English   中英

VB.NET打开到Postgres的连接

[英]VB.NET open connection to Postgres

我正在一个需要连接到Postgresql的项目中,我已经在下面尝试过此代码:

Public Module Main
Dim _desktop As Desktop = Agent.Desktop

Public Sub Main(args As IDictionary(Of String, Object))
    Dim conn As New Odbc.OdbcConnection
    conn.ConnectionString = "Driver={PostgreSQL ANSI};database=postgres;server=127.0.0.1;port=5432;uid=postgres;sslmode=disable;readonly=0;protocol=9.4;User ID=postgres;password=12345678;"

    conn.Open()
    If conn.State = ConnectionState.Open Then
        MsgBox("Connected To PostGres", MsgBoxStyle.MsgBoxSetForeground)
    End If
    conn.Close()
End Sub
End Module

但我有一个问题, Type 'Odbc.OdbcConnection' is not defined. 有没有人可以帮助我解决问题? 该错误表明我尚未导入依赖项,但我不知道正确的导入方式。

此代码可以帮助您:

 Dim MyCon As New Odbc.OdbcConnection
MyCon.ConnectionString = "Driver={PostgreSQL ANSI};database=database_name;server=127.0.0.1;port=5432;uid=postgres;sslmode=dis
 able;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

确保输入正确的IP,用户名和密码。但是在进行所有操作之前,请先安装必需的驱动程序

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM