准备:
服务器系统:centos 5.9
postgresql 8.0
1.首先要确保你的postgresql在服务器上已经安装成功可以在你的客户端计算机上下一个pgAdmin,连接远程的postgresql
2.连接时要确保服务器上的5432端口开放
3.连接时要确保服务器上的postgresql配置文件都已配置
上诉三点部分有截图,接下来进行vb.net中对该数据库的连接
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
最后实现连接成功。