Selasa, 04 Januari 2011

Koneksi VB dengan MySql

Posted by Ayo Belajar at 21.14
Kali ini posting tentang source code koneksi VB ke MySql.
ok g usah panjang lebar langsung aja ke TKP.
Private Sub buat_koneksi()
Dim ConnString As String
Dim db_name As String
Dim db_server As String
Dim db_port As String
Dim db_user As String
Dim db_pass As String
'//error traping
On Error GoTo buat_koneksi_Error
'/isi variable
db_name = "databaseku"
db_server = "localhost" 'ganti jika server anda ada di komputer lain
db_port = "3306" 'default port is 3306
db_user = "root" 'sebaiknya pakai username lain.
db_pass = "password_anda"
'/buat connection string
ConnString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_user & ";PWD=" & db_pass & ";PORT=" & db_port & ";OPTION=3"
'/buka koneksi
With Conn
.ConnectionString = ConnString
.Open
End With
'___________________________________________________________
On Error GoTo 0
Exit Sub

buat_koneksi_Error:
MsgBox "Ada kesalahan dengan server, periksa apakah server sudah berjalan !", vbInformation, "Cek Server"
End Sub


Semoga bermanfaat,dan silahkan mencoba.

0 comments:

Posting Komentar

 

Copyright © 2011 Blog Amburadul | Design by Kenga Ads-template