微软MSDN中,在ADP项目中创建ADP的数据库的默认连接的代码
Public Function sCreateConnection(sSvrName As String, sUID As String, sPWD As String, sDatabase As String) As String '******************************************************************** '该函数在ADP中检查连接,如果没有,它将通过输入参数创建一个连接 ' '输入: ' sSvrName 数据库服务器名 ' sUID 用户名 ' sPWD 口令 ' sDatabase MSDE数据库名 ' '输出: ' 连接状态 ' '********************************************************************
On Error GoTo sCreateConnectionTrap: If Application.CurrentProject.BaseConnectionString = "" Then '表示ADP处于无连接状态 sConnectionString = "PROVIDER=SQLOLEDB.1;PASSWORD=" & sPWD _ & ";PERSIST SECURITY INFO=TRUE;USER ID=" & sUID & "; _ INITIAL CATALOG=" & sDatabase & ";DATA SOURCE=" & sSvrName Application.CurrentProject.OpenConnection sConnectionString sCreateConnection = "创建了到 " & sDatabase & " 数据库的连接!" Else '连接已存在 sCreateConnection = "已经存在到 " & sDatabase & " 数据库的连接!" End If sCreateConnectionExit: Exit Function
sCreateConnectionTrap: sCreateConnection = Err.Description Resume sCreateConnectionExit
End Function
-------------------------------------------
此例程将从 ADP 删除连接,使其处于无连接状态。 Sub MakeADPConnectionless() Application.CurrentProject.CloseConnection '关闭连接 Application.CurrentProject.OpenConnection '将连接设置为无
End Sub
|