修复ACCESS数据库遇到一个比较奇怪的问题,请各位大虾指教!!先谢谢了!!! ( 积分: 50 )

  • 主题发起人 主题发起人 kitewgd
  • 开始时间 开始时间
K

kitewgd

Unregistered / Unconfirmed
GUEST, unregistred user!
我用如下程序修复ACCESS数据库:
function GetTempPathFileName(): String;
var
SPath,SFile:array [0..254] of char;
begin
GetTempPath(254,SPath);
GetTempFileName(SPath,'~CP',0,SFile);
Result := SFile;
DeleteFile(PChar(Result));
end;

function CompactDatabase(AFileName,APassWord:string): Boolean;
var
vJE: OleVariant;
STempFileName: String;
begin
STempFileName := GetTempPathFileName;
try
vJE := CreateOleObject('JRO.JetEngine');
vJE.CompactDatabase(Format(SConnectionString,[AFileName,APassWord]),
Format(SConnectionString,[STempFileName,APassWord]));
Result := CopyFile(PChar(STempFileName),PChar(AFileName),false);
DeleteFile(STempFileName);
except
Result := False;
end;
end;

调用:
if CompactDatabase('D:/test.mdb','password') then
ShowMessage('Repair Successfull!');
当执行如上程序时出现了如下错误,不知为何,请各位大虾指教,谢谢了!
ERROR: 不可识别的数据库格式:D:/test.mdb.
 
我用如下程序修复ACCESS数据库:
function GetTempPathFileName(): String;
var
SPath,SFile:array [0..254] of char;
begin
GetTempPath(254,SPath);
GetTempFileName(SPath,'~CP',0,SFile);
Result := SFile;
DeleteFile(PChar(Result));
end;

function CompactDatabase(AFileName,APassWord:string): Boolean;
var
vJE: OleVariant;
STempFileName: String;
begin
STempFileName := GetTempPathFileName;
try
vJE := CreateOleObject('JRO.JetEngine');
vJE.CompactDatabase(Format(SConnectionString,[AFileName,APassWord]),
Format(SConnectionString,[STempFileName,APassWord]));
Result := CopyFile(PChar(STempFileName),PChar(AFileName),false);
DeleteFile(STempFileName);
except
Result := False;
end;
end;

调用:
if CompactDatabase('D:/test.mdb','password') then
ShowMessage('Repair Successfull!');
当执行如上程序时出现了如下错误,不知为何,请各位大虾指教,谢谢了!
ERROR: 不可识别的数据库格式:D:/test.mdb.
 
版本问题,你用ACCESS97格式的数据库就没问题
win98 下没有此问题,win2000下有此问题,xp下没测试
 
接受答案了.
 
后退
顶部