Posted by: harisanto | 24 December 2007

.Net: MySQL Connection With ADODB

Banyak cara yang dipakai untuk koneksi ke database MySQL. Dari cara yang sangat gampang, tinggal klak-klik sana-sini aja udah bisa menghubungkan kita dengan database. Tapi, apakah cara itu sudah efektif? kenapa ya aku kok kurang setuju. aku lebih memilih cara2 yang konvensional alias manual, alasannya akan lebih mudah dalam maintenance dan akan lebih fleksible.

Module databases

Public CnActiveConnection As New ADODB.Connection

Public Sub MySQL_Connection(ByVal host As String, ByVal database As String, ByVal user As String, ByVal password As String)

CnActiveConnection = New ADODB.Connection
tSQL = “DRIVER={MySQL ODBC 3.51 Driver};” _

& “SERVER=” & host & “;” _
& “DATABASE=” & database & “;” _
& “UID=” & user & “;” _
& “PWD=” & password & “;” _
& “OPTION= ” & 3

Try

CnActiveConnection.Open(tSQL)
CnActiveConnection.CommandTimeout = 0
CnActiveConnection.CursorLocation = ADODB.CursorLocationEnum.adUseClient
xcon = True
Catch ex As Exception
xcon = False

End Try

End Sub

End Module
Semoga function ini Berguna, thanks…

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.