如何在VBA或者JET SQL下编程更改ACCESS MDB 数据库口令(密码)?

来源:转载

记住,修改密码请使用独占打开的方式

方法一:

 

'要修改密码可以使用NewPassword方法:

Dim Db As DAO.Database

SetDb = OpenDatabase("C:\MyDocuments\MyDB.mdb", True, _

False, ";pwd=MyPassword1")

Db.NewPassword "MyPassword1", "MyPassword2"

Db.Close

 

方法二:

 

'也可以使用CompactDatabase方法:

DBEngine.CompactDatabase "C:\MyDocuments\Test.mdb", _

"C:\MyDocuments\TestII.MDB", dbLangGeneral & ";pwd=MyNewPWD", _

dbVersion30, ";pwd=MyPassword1"

 

方法三:

 

'在ADO下执行,且必须独占打开MDB文件

dim conn

Set conn = CreateObject("adodb.connection")

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=

c:\TEMP\test.mdb;Mode=Share Deny Read|Share Deny Write;Persist Security Info=False;Jet OLEDB:Database Password=老密码"

conn.Open

conn.Execute "ALTER DATABASE PASSWORD 新密码 老密码 "

conn.Close

'取消密码

conn.Execute "ALTER DATABASE PASSWORD [] 老密码 "

adModeUnknown:缺省。当前的许可权未设置

adModeRead:只读

adModeWrite:只写

adModeReadWrite:可以读写

adModeShareDenyRead:阻止其它Connection对象以读权限打开连接

adModeShareDenyWrite:阻止其它Connection对象以写权限打开连接

adModeShareExclusive:阻止其它Connection对象以读写权限打开连接

adModeShareDenyNone:阻止其它Connection对象以任何权限打开连接

分享给朋友:
您可能感兴趣的文章:
随机阅读: