vb.net连接远程服务器上的postgreSql

前端之家收集整理的这篇文章主要介绍了vb.net连接远程服务器上的postgreSql前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_0@准备:

@H_403_0@ 服务器系统:centos 5.9

@H_403_0@ postgresql 8.0

@H_403_0@1.首先要确保你的postgresql在服务器上已经安装成功可以在你的客户端计算机上下一个pgAdmin,连接远程的postgresql

@H_403_0@2.连接时要确保服务器上的5432端口开放

@H_403_0@3.连接时要确保服务器上的postgresql配置文件都已配置

@H_403_0@

@H_403_0@

@H_403_0@

@H_403_0@

@H_403_0@上诉三点部分有截图,接下来进行vb.net中对该数据库的连接

@H_403_0@1.安装Npgsql驱动,从网站

http://pgfoundry.org/projects/npgsql/下载


2.解压Npgsql驱动包,在你的vb.net项目中引用Npgsql.dll


3.代码实现如下

Imports Npgsql
Public Class Form1
Public Autumn_CString As String
Public ESQ_name = ""
Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click
Dim conn As NpgsqlConnection = New NpgsqlConnection("Server=192.168.210.250;Port=5432;User Id=postgres;Password=postgres;Database=help;")
conn.Open()
Dim Command As NpgsqlCommand = New NpgsqlCommand("select * from kefu",conn)
Try
Dim dr As NpgsqlDataReader = Command.ExecuteReader()
dr.Read()
TextBox1.Text = dr(2).ToString
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub


Private Sub TextBox1_TextChanged(sender As Object,e As EventArgs) Handles TextBox1.TextChanged
End Sub


Private Sub TextBox2_TextChanged(sender As Object,e As EventArgs) Handles TextBox2.TextChanged
End Sub
End Class

最后实现连接成功。

猜你在找的VB相关文章