SHARE
TWEET

VB 6 : Test Koneksi Ke Database Server

stevennathaniel May 1st, 2016 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Koneksi As New ADODB.Connection
  2.  
  3.  
  4. Private Sub Command1_Click()
  5.  
  6. Dim ConnString As String
  7.  
  8. Dim db_name As String
  9.  
  10. Dim db_server As String
  11.  
  12. Dim db_port As String
  13.  
  14. Dim db_user As String
  15.  
  16. Dim db_pass As String
  17.  
  18. ' Jebakan error
  19.  
  20. On Error GoTo buat_koneksi_Error
  21.  
  22. ' isi variabel
  23.  
  24. db_name = "latihan"
  25.  
  26. db_server = "localhost"
  27.  
  28. db_port = "3306"
  29.  
  30. db_user = "root"
  31.  
  32. db_pass = "kucing"
  33.  
  34.  
  35. 'Bikin string koneksi
  36.  
  37. stringKoneksi = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_user & ";PWD=" & db_pass & ";PORT=" & db_port & ";OPTION=3"
  38.  
  39. ' Open Connection
  40.  
  41. With Koneksi
  42.  
  43. .ConnectionString = stringKoneksi
  44.  
  45. .Open
  46.    
  47.     End With
  48.    
  49.     MsgBox "Terkoneksi"
  50.    
  51.    
  52.     On Error GoTo 0
  53.    
  54.     Exit Sub
  55.    
  56. buat_koneksi_Error:
  57.    
  58.     MsgBox "Error, Periksa apakah server dihidupkan", vbInformation, "Periksa Server"
  59.  
  60. End Sub
  61.  
  62.  
  63.  
  64. Private Sub Form_Unload(Cancel As Integer)
  65.  
  66. If Koneksi.State = adStateOpen Or Koneksi.State = adStateConnecting Then
  67.  
  68. Koneksi.Close
  69.  
  70. Set Koneksi = Nothing
  71.  
  72. End If
  73.  
  74.  
  75.  
  76. End Sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top