Created
October 29, 2017 19:47
-
-
Save vbcupu/fd5175a6a54a2553806a88654078d3ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim dbconn As ADODB.Connection | |
Dim rs As ADODB.Recordset | |
Dim strSQL As String | |
Dim ConsTring As String | |
Private Sub cmdKoneksi_Click() | |
Call OpenConnection | |
End Sub | |
Private Sub OpenConnection() | |
On Error GoTo err: | |
Set dbconn = New ADODB.Connection | |
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 | |
db_name = "toko" | |
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 = "" | |
'/buat connection string | |
ConsTring = "Driver={MySQL ODBC 5.3 ANSI Driver};Server=" & db_server & ";Database=" & db_name & ";User=" & db_user & ";Password= " & db_pass & ";Option=3;" | |
dbconn.ConnectionString = ConsTring | |
If dbconn.State = 1 Then | |
dbconn.Close | |
dbconn.Open | |
Else | |
dbconn.Open | |
End If | |
Call MsgBox("Koneksi Berhasil") | |
Exit Sub | |
err: | |
Call MsgBox("Koneksi Gagal") | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment