会员登录 - 用户注册 - 网站地图 Office中国(office-cn.net),专业Office论坛
当前位置:主页 > 技巧 > Access技巧 > DAO/ADO/ADP > 正文

打开带密码的数据库/修改密码/创建组和用户

时间:2005-02-05 13:59 来源:vbcode 作者:Chrisnbs… 阅读:

一。首先在模块中添加如下代码。

对象类型是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)

顶一下
(0)
0%
踩一下
(0)
0%
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价: