打开带密码的数据库/修改密码/创建组和用户
一。首先在模块中添加如下代码。
对象类型是DAO/ADO
============
对 DAO 定义
dim wkData as dao.workspace
Dim dbData as dao.Database
============
对ADO定义
dim cnn as new connection
二。在模块中创建如下过程
Option Explicit
'* 使用DAO打开带密码数据库
Sub OpendatabaseWithPassword(DB As Object, strDatabase As String, strPass As String)
Set DB = DBEngine.OpenDatabase(App.Path & "\" & strDatabase, False, False, ";pwd=" & strPass)
End Sub
'* 使用ADO打开带密码数据库
Sub OpenConnectionWithPassword(DB As Object, strProvider, strDataSource As String, strPassWord As String)
DB.Open _
strProvider & _
strDataSource & _
strPassWord
End Sub
'* 使用DAO修改数据库密码
Sub ChangeDBPassword_DAO(DB As Object, strDatabase As String, strOldPass As String, strNewPass As String)
Set DB = DBEngine.OpenDatabase(App.Path & "\" & strDatabase, True, False, ";pwd=" & strOldPass)
DB.NewPassword strOldPass, strNewPass
DB.Close
End Sub
'* 使用DAO修改用户密码
Sub ChangeUserPassword_DAO(DB As Object, strOldPass As String, strNewPass As String)
DBEngine.SystemDB = "c:\win98\system\system.mdw"
Set DB = DBEngine.CreateWorkspace("", "Admin", strOldPass)
DB.Users("Admin").NewPassword strOldPass, strNewPass
DB.Close
End Sub
'* 使用ADO修改用户密码
'* Assumes that the Admin user doesn't currently have a password set
'* Provider=Microsoft.Jet.OLEDB.4.0;
Sub ChangeUserPassword_ADO(DB As Object, strProvider, strDataSource As String, strSystem As String, strOldPassword As String, strNewPassword As String)
DB.ActiveConnection = _
strProvider & _
strDataSource & _
strSystem
DB.Users("Admin").ChangePassword strOldPassword, strNewPassword
Set DB = Nothing
End Sub
'* 使用DAO添加新用户 组 密码
Sub CreateUserGroup_DAO(DB As Object, User As Object, NewUser As String, strPID As String, strPassWord As String, wrkPass As String)
DBEngine.SystemDB = "c:\win98\system\system.mdw"
Set DB = DBEngine.CreateWorkspace("", "Admin", wrkPass)
Set User = DB.CreateUser(NewUser, strPID, strPassWord)
DB.Users.Append User
DB.Close
End Sub
'* 添加新用户到组 -tmtony
Sub AddUserToGroup(DB As Object, strPass As String, strNewUser As String, strNewGroup)
DBEngine.SystemDB = "c:\win98\system\system.mdw"
Set DB = DBEngine.CreateWorkspace("", "Admin", strPass)
DB.Users(strNewUser).Groups.Append _
DB.Users(strNewUser).CreateGroup(strNewGroup)
DB.Close
End Sub
三。使用方法
OpenDatabaseWithPassWord(dbData, "Test.mdb", "vbcode")
OpenConnectionWithPassWord(cnn,"Provider=Microsoft.Jet.OLEDB.4.0;","Data Source=" + app.path + "\"+ "Test.mdb","vbcode")
原作者:Chris Cabayao
原文:http://www.vbcode.com/asp/showsn.asp?theID=1614
翻译:tmtony(王宇虹) http://www.office-cn.net tmtony@21cn.com
(责任编辑:admin)
- ·用DAO或ADO正确访问Access 2000
- ·Access开发网络共享版技巧(多人同时操
- ·access中ADO与DAO格式的区别和写法【总
- ·access执行操作查询的几种方法对比
- ·Access中CurrentDb().Execute 和DoCmd.
- ·[源创技巧]在ACCESS中使用代码来自动创
- ·更新访问权限 (Jet) 数据库中的 40 多
- ·【实例】ADO代码计算余额法
- ·DAO实现的子窗体记录分页显示
- ·分别使用DAO和ADO连接外部数据库和Sql
- ·怎样判断一个表是否存在于数据库中? (D
- ·处理加了密码的MDB文件
- ·谈ADO访问不同数据库的差别
- ·DAO基础(4)
- ·DAO基础(3)
- ·DAO基础(2)