Home about IT Motivation Course Sales Project About Me

Sunday, February 28, 2010

conection ADODC dengan script

membuat conection database dengan adodb sepertinya lebih mudah dengan script keuntungannya:
- kalo applikasinya makin rumit, tak perlu setting ADODC properties one by one.
- mudah dirubah, misal ketika di copykan ke server orang lain dengan nama server dan password berbeda.

berikut contoh scriptnya bila dijadikan modul

Public Function Koneksi_Database() As Boolean
On Error GoTo Pesan
If db.State = adStateOpen Then
db.Close
End If


db.Open "Provider=SQLOLEDB.1;" & _
"Persist Security Info=False;" & _
"User ID=sa;" & _
"Password=password;" & _
"Initial Catalog=DBName;" & _
"Data Source=ServerName"
db.CursorLocation = adUseClient
Koneksi_Database = True

Exit Function
Pesan:
Koneksi_Database = False
MsgBox "Koneksi ke server tidak berhasil !!!", 16, "ERROR"
End
End Function

No comments: