VBA 数据库链接之ADODB

Public gpgDB As ADODB.Connection

Function DbConnect(ip As String, db As String, user As String, password As String) As Boolean

On Error GoTo ThisEnd

    Set gpgDB = Nothing

    Set gpgDB = New ADODB.Connection

    gpgDB.Open "Provider=PostgreSQL;Data Source=" + ip + ";location=" + db, user, password

    If gpgDB.State = adStateClosed Then

        MsgBox "Connect error!"

        DbConnect = False

        Exit Function

    End If

    DbConnect = True

ThisEnd:

End Function

猜你喜欢

转载自xieyunbiao.iteye.com/blog/2275212
vba
今日推荐