如何用delphi给access加密码

cailiantao 2003-02-12 09:51:17
//创建Access
AccessApplication.Connect;
AccessApplication.NewCurrentDatabase('c:\a.mdb');
AccessApplication.CurrentDb.NewPassword('""','clt');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AccessApplication.CloseCurrentDatabase;
AccessApplication.Disconnect;
用NewPassword但提示密码错误。
还有我还试过:
NewPassword('','clt');
NewPassword('''' + '' + '''','clt');
还是不行。
不知有谁能帮我。

...全文
84 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
anh 2003-02-13
  • 打赏
  • 举报
回复
access本来就可以加密的。
cailiantao 2003-02-13
  • 打赏
  • 举报
回复
试呢一下CompactDatabase ,加密码是可以,但是要多一个文件出来。
还有,不知有没有人试过createdatabase,
我试呢一下,提示什么smia?(不知名字对不对)

to anh(hananying)
我是要在delphi中,创建access是对access加上密码。不用用户操作的。
cailiantao 2003-02-12
  • 打赏
  • 举报
回复
CompactDatabase 这个方法是用来压缩access数据库?
那NewPassword到底有没有用?
照帮助上讲的可以1、加密码;2、修改密码;3、撤消密码
但是就是不能加密码。
shxhark 2003-02-12
  • 打赏
  • 举报
回复
Function SetMDBPassWord(FileName:String;OldPWD:String;NewPWD:String):Boolean;
var
TempStr:String;
begin
with Frm_NoteBook.ADOConnection1 do begin
Connected:=false;
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;' +
'Data Source='+ FileName +
';Mode=Share Deny Read|Share Deny Write;Extended Properties="";' +
'Jet OLEDB:System database="";' +
'Jet OLEDB:Registry Path="";' +
'Jet OLEDB:Database Password='+ OldPWD +';'+
'Jet OLEDB:Engine Type=5;' +
'Jet OLEDB:Database Locking Mode=1;' +
'Jet OLEDB:Global Partial Bulk Ops=2;' +
'Jet OLEDB:Global Bulk Transactions=1;' +
'Jet OLEDB:New Database Password="";' +
'Jet OLEDB:Create System Database=False;' +
'Jet OLEDB:Encrypt Database=False;' +
'Jet OLEDB:Don''t Copy Locale on Compact=False;' +
'Jet OLEDB:Compact Without Replica Repair=False;' +
'Jet OLEDB:SFP=False';
try
connected:=true;
if trim(OldPWD)='' then OldPWD:='null';
if trim(NewPWD)='' then NewPWD:='null';
TempStr:='ALTER Database Password '+ NewPWD + ' ' + OldPWD;
Execute(TempStr,cmdText,[eoExecuteNoRecords]);
result:=true;
except
msgbox('数据文件处理发生错误!','',16);
result:=false;
end;
end;
end;
Billy_Chen28 2003-02-12
  • 打赏
  • 举报
回复
通过adoconnection控件连接数据库是会出现“数据连接属性”对话框,在“所有”标签下的Jet OLEDB:Database Password属性,将其值修改为数据库的密码。
还有一个比较重要的问题是在“连接”标签下选中空白密码。

还可以带密码压缩:dao.CompactDatabase(FileName,TempFile,'',0,';pwd=123456789');

还有Diamond Access也能够给Access数据库加密码
sevencat 2003-02-12
  • 打赏
  • 举报
回复
不好意思,贴错了。
sevencat 2003-02-12
  • 打赏
  • 举报
回复
NewPassword Method Example

This example asks the user for a new password for user Pat Smith. If the input is a string between 1 and 14 characters long, the example uses the NewPassword method to change the password. The user must be logged on as Pat Smith or as a member of the Admins group.

Sub NewPasswordX()

Dim wrkDefault As Workspace
Dim usrNew As User
Dim grpNew As Group
Dim grpMember As Group
Dim strPassword As String

' Get default workspace.
Set wrkDefault = DBEngine.Workspaces(0)

With wrkDefault

' Create and append new user.
Set usrNew = .CreateUser("Pat Smith", _
"abc123DEF456", "Password1")
.Users.Append usrNew

' Create and append new group.
Set grpNew = .CreateGroup("Accounting", _
"UVW987xyz654")
.Groups.Append grpNew

' Make the new user a member of the new group.
Set grpMember = usrNew.CreateGroup("Accounting")
usrNew.Groups.Append grpMember

' Ask user for new password. If input is too long, ask
' again.
Do While True
strPassword = InputBox("Enter new password:")
Select Case Len(strPassword)
Case 1 To 14
usrNew.NewPassword "Password1", strPassword
MsgBox "Password changed!"
Exit Do
Case Is > 14
MsgBox "Password too long!"
Case 0
Exit Do
End Select
Loop

' Delete new User and Group objects because this
' is only a demonstration.
.Users.Delete "Pat Smith"
.Groups.Delete "Accounting"

End With

End Sub
cailiantao 2003-02-12
  • 打赏
  • 举报
回复
这AccessApplication是用delphi导入的为access_Tlb下的一个控件。
还有NewPassword方法在dao35.hlp帮助文件中可以找到的
我根据上面的说明来做,就是提示密码错误。
不知有没有人通过这个方式解决?
sevencat 2003-02-12
  • 打赏
  • 举报
回复
这种实现是COM晚绑定,也可以先导入ADOX类型库,用ADO大概做不了这种事。
ysai 2003-02-12
  • 打赏
  • 举报
回复
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1601151
//=============================================================================
// Procedure: CreateAccessFile
// Author : ysai
// Date : 2003-01-27
// Arguments: FileName:String;PassWord:string=''
// Result : boolean
//=============================================================================
function CreateAccessFile(FileName:String;PassWord:string=''):boolean;
//建立Access文件,如果文件存在则失败
var
STempFileName:string;
vCatalog:OleVariant;
begin
STempFileName:=GetTempPathFileName;
try
vCatalog:=CreateOleObject('ADOX.Catalog');
vCatalog.Create(format(SConnectionString,[STempFileName,PassWord]));
result:=CopyFile(PChar(STempFileName),PChar(FileName),True);
DeleteFile(STempFileName);
except
result:=false;
end;
end;

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧