设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

1970-1-1 08:00| 发布者: ChrisnbspCabaya| 查看: 2136| 评论: 0

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

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

最新评论

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2025-4-4 05:17 , Processed in 0.071342 second(s), 17 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部