Sub MakeADPConnectionless() Application.CurrentProject.CloseConnection '关闭连接 Application.CurrentProject.OpenConnection '将连接设置为无 End Sub |
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.BaseC 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 sCreateC & sDatabase & " 数据库的连接!" Else '连接已存在 sCreateC & sDatabase & " 数据库的连接!" End If sCreateConnectionExit: Exit Function sCreateConnectionTrap: sCreateConnection = Err.Description Resume sCreateConnectionExit End Function |
以下是引用liujunqun在2002-3-27 17:18:03的发言:
我用过字符串指明数据库源和用户名等等连接数据库服务器,没有用DSN,不用配置客户端或ODBC,那样太麻烦。如果报错就调用系统链接窗体重新设置。
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) | Powered by Discuz! X3.3 |