[英]VB.NET open connection to Postgres
I am working on a project that require to connect to Postgresql, I have tried this code below: 我正在一个需要连接到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
But I have the problem Type 'Odbc.OdbcConnection' is not defined.
但我有一个问题,
Type 'Odbc.OdbcConnection' is not defined.
. 。 Is there anyone can help me to resolve problem?
有没有人可以帮助我解决问题? The error indicates that I has not imported the dependency, but I dont't know right way to import.
该错误表明我尚未导入依赖项,但我不知道正确的导入方式。
This code might help you : 此代码可以帮助您:
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
Make sure you type the correct IP,username and password.But before everything, please install required drivers 确保输入正确的IP,用户名和密码。但是在进行所有操作之前,请先安装必需的驱动程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.