Public Function saConnect(ByVal strServer As String, ByVal strDatabase As String, _
ByVal strUsername As String, ByVal strPassword As String) As Boolean
On Error GoTo err
Connect:
Dim strCn As String
strCn = "PROVIDER=SQLOLEDB.1;"
'strCn = strCn & "Workstation Id = HY"
strCn = strCn & "DATA SOURCE=" & strServer & ";"
strCn = strCn & "INITIAL CATALOG=" & strDatabase & ";"
strCn = strCn & "USER ID=sa;"
strCn = strCn & "PASSWORD=;"
strCn = strCn & "PERSIST SECURITY INFO=TRUE;"
strCn = strCn & "Use Procedure for Prepare=1;"
strCn = strCn & "Auto Translate=True;"
strCn = strCn & "Packet Size=4096;"
'Debug.Print strCn
CurrentProject.OpenConnection strCn
theConnect = True
Exit Function
err:
MsgBox "错误代码: " & err.Number & vbCrLf & vbCrLf & _
"错误描述: " & err.Description, vbCritical + vbOKOnly, theTitle
End Function
Wangjerry能解释一下上述代码吗?这样我就能灵活运用了。其实最主要是想知道当中那句是连接ADP数据库的。