对access数据库维护

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
{*************************************************************** *
* Unit Name: unAccessTools
* Purpose : Provide tools to compact and repair Access database.
*
****************************************************************}
unit unAccessTools;
interface
uses Sysutils,ComObj,Dialogs;
function DaoActive(var DaoObject:OleVariant):Boolean;
function DaoCompactDB(const FileName:string):Boolean;
function DaoRepairDB(const FileName:string):Boolean;
implementation
function DaoActive(var DaoObject:OleVariant):Boolean;
begin
Result:=False;
try
DaoObject:=GetActiveOleObject('DAO.DBEngine.36');
Result:=True;
except
try
DaoObject:=CreateOleObject('DAO.DBEngine.36');
Result:=True;
except
DaoObject:=Null;
end;
end;
end;
//压缩Access数据库
function DaoCompactDB(const FileName:string):Boolean;
var
db:OleVariant;
TempFile:string;
begin
Result:=False;
try
if not DaoActive(db) then
Exit;
try
TempFile:=ExtractFilePath(FileName)+'msaTemp.mdb';
db.CompactDatabase(FileName,TempFile);
DeleteFile(FileName);
RenameFile(TempFile,FileName);
Result:=True;
except
on E:EOleException do
ShowMessage(E.Message);
end
finally
db:=Unassigned;
end;
end;
//修复Access数据库
function DaoRepairDB(const FileName:string):Boolean;
var
db:OleVariant;
begin
Result:=False;
try
if not DaoActive(db) then
Exit;
try
db.RepairDatabase(FileName);
Result:=True;
except
on E:EOleException do
ShowMessage(E.Message);
end
finally
db:=Unassigned;
end;
end;
end.
 
 

Similar threads

I
回复
0
查看
547
import
I
I
回复
0
查看
571
import
I
I
回复
0
查看
720
import
I
I
回复
0
查看
618
import
I
后退
顶部