• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi修改Access密码,压缩与修复,建立Access数据库文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
  1 unit UAccessOperate;
  2 
  3 interface
  4 
  5 uses Windows, Sysutils, ComObj, Dialogs, ActiveX;
  6 
  7 
  8 
  9 //修改ACCESS数据库密码
 10 function ChangeDatabasePassword(AFileName,AOldPassWord,ANewPassWord:string):boolean;
 11 
 12 //压缩与修复数据库,覆盖源文件
 13 function CompactDatabase(AFileName,APassWord:string):boolean;
 14 
 15 //建立Access文件,如果文件存在则失败
 16 function CreateAccessFile(FileName:String;PassWord:string=''):boolean;
 17 
 18 implementation
 19 
 20 //声明连接字符串
 21 Const
 22 SConnectionString       = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'
 23 
 24                                +'Jet OLEDB:Database Password=%s;';
 25 
 26 
 27 
 28 //=============================================================================
 29 
 30 // Procedure: GetTempPathFileName
 31 
 32 // Author   : ysai
 33 
 34 // Date     : 2003-01-27
 35 
 36 // Arguments: (None)
 37 
 38 // Result   : string
 39 
 40 //=============================================================================
 41 
 42 function GetTempPathFileName():string;
 43 
 44 //取得临时文件名
 45 var
 46 SPath,SFile:array [0..254] of char;
 47 begin
 48 GetTempPath(254,SPath);
 49 GetTempFileName(SPath,'~SM',0,SFile);
 50 result:=SFile;
 51 DeleteFile(PChar(result));
 52 end;
 53 
 54 
 55 
 56 //=============================================================================
 57 
 58 // Procedure: CreateAccessFile
 59 
 60 // Author   : ysai
 61 
 62 // Date     : 2003-01-27
 63 
 64 // Arguments: FileName:String;PassWord:string=''
 65 
 66 // Result   : boolean
 67 
 68 //=============================================================================
 69 //建立Access文件,如果文件存在则失败
 70 function CreateAccessFile(FileName:String;PassWord:string=''):boolean;
 71 var
 72 STempFileName:string;
 73 vCatalog:OleVariant;
 74 begin
 75 STempFileName:=GetTempPathFileName;
 76 try
 77    vCatalog:=CreateOleObject('ADOX.Catalog');
 78    vCatalog.Create(format(SConnectionString,[STempFileName,PassWord]));
 79    result:=CopyFile(PChar(STempFileName),PChar(FileName),True);
 80    DeleteFile(STempFileName);
 81 except
 82    result:=false;
 83 end;
 84 end;
 85 
 86 
 87 
 88 //=============================================================================
 89 
 90 // Procedure: CompactDatabase
 91 
 92 // Author   : ysai
 93 
 94 // Date     : 2003-01-27
 95 
 96 // Arguments: AFileName,APassWord:string
 97 
 98 // Result   : boolean
 99 
100 //=============================================================================
101 
102 function CompactDatabase(AFileName,APassWord:string):boolean;
103 //压缩与修复数据库,覆盖源文件
104 var
105 STempFileName:string;
106 vJE:OleVariant;
107 begin
108 STempFileName:=GetTempPathFileName;
109 try
110    vJE:=CreateOleObject('JRO.JetEngine');
111    vJE.CompactDatabase(format(SConnectionString,[AFileName,APassWord]),
112        format(SConnectionString,[STempFileName,APassWord]));
113    result:=CopyFile(PChar(STempFileName),PChar(AFileName),false);
114    DeleteFile(STempFileName);
115 except
116    result:=false;
117 end;
118 end;
119 
120 
121 
122 //=============================================================================
123 // Procedure: ChangeDatabasePassword
124 // Author   : ysai
125 // Date     : 2003-01-27
126 // Arguments: AFileName,AOldPassWord,ANewPassWord:string
127 // Result   : boolean
128 //=============================================================================
129 //修改ACCESS数据库密码
130 function ChangeDatabasePassword(AFileName,AOldPassWord,ANewPassWord:string):boolean;
131 var
132   STempFileName:string;
133   vJE:OleVariant;
134 begin
135 STempFileName:=GetTempPathFileName;
136 try
137    vJE:=CreateOleObject('JRO.JetEngine');
138    vJE.CompactDatabase(format(SConnectionString,[AFileName,AOldPassWord]),
139                        format(SConnectionString,[STempFileName,ANewPassWord]));
140    result:=CopyFile(PChar(STempFileName),PChar(AFileName),false);
141    DeleteFile(STempFileName);
142 except
143    result:=false;
144 end;
145 end;
146 
147 end.

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
在Delphi.net中使用内联代码功能发布时间:2022-07-18
下一篇:
Delphi 调用BarTender打印条码发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap