推荐资料自学网址:http://www.51zxw.net/study.asp?vip=10241777
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=" & strUsername & ";" '用户名
strCn = strCn & "PASSWORD=" & strPassword & ";" '密码
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
i = True
theConnect = True
Exit Function
err:
i = False
MsgBox "错误代码: " & err.Number & vbCrLf & vbCrLf & _
"错误描述: " & err.Description, vbCritical + vbOKOnly, theTitle
联系客服