Public Function Koneksi_SQLServer(namaserver, namadb, userid, userpass) As Boolean On Error GoTo KoneksiSalah Dim cn_SQLServer As ADODB.Connection Set cn_SQLServer = New ADODB.Connection Koneksi_SQLServer = False cn_SQLServer.Open "Provider=SQLOLEDB.1;" & _ "Persist Security Info=False;" & _ "User ID=" & userid & ";" & _ "Password=" & userpass & ";" & _ "Initial Catalog=" & namadb & ";" & _ "Data Source=" & namaserver cn_SQLServer.Close Set cn_SQLServer = Nothing Koneksi_SQLServer = True Exit Function KoneksiSalah: Select Case Err.Number Case -2147467259 ' Server salah MsgBox "Nama server atau database tidak ditemukan" Case -2147217843 ' User atau password salah MsgBox "Username atau password yang anda masukkan salah" End Select Koneksi_SQLServer = False End Function
Tuesday, 10 May 2011
Koneksi VB dan SQL Server
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment