我已通过以下步骤将.mdb数据库转换为.accdb数据库:
https://support.office.com/en-us/article/Convert-a-database-to-the-accdb-file-format-69abbf06-8401-4cf3-b950-f790fa9f359c
(使用MS Access 2010)
转换后,.accdb文件以以下内容开头:
(database.accdb,用十六进制编辑器查看文件头),这就是我想要的…
00 01 00 00 53 74 61 6E 64 61 72 64 20 41 43 45 20 44 42 00 02 00 00 00 B5 6E 03 62 60 09 C2 55 E9 A9 67 72 40 3F 00 9C 7E 9F 90 FF 85 9A 31 C5
....Standard ACE DB.....µn.b`.ÂUé©gr@?.œ~Ÿ.ÿ…š1Å
打开数据库、删除表、重新创建表并使用tfdconnection/tfdphysmaccessdriverlink/tfdbatchmove/tfdbatchmovedatasetreader/tfdbatchmovedatasetwriter和以下代码执行一些插入操作
FAccessDB := TFDConnection.Create(Self);
FAccessDB.Name := '';
FAccessDB.Params.Clear;
FAccessDB.Params.Add('DriverID=MSAcc_Direct');
FAccessDB.LoginPrompt := False;
// FDPhysMSAccessDriverLink1
FFDPhysMSAccessDriverLink1 := TFDPhysMSAccessDriverLink.Create(Self);
FFDPhysMSAccessDriverLink1.Name := '';
FFDPhysMSAccessDriverLink1.DriverID := 'MSAcc_Direct';
// Table_Out
FFDTable_Out := TFDTable.Create(Self);
FFDTable_Out.Name := '';
FFDTable_Out.Connection := FAccessDB;
// FDBatchMove1
FFDBatchMove1 := TFDBatchMove.Create(Self);
FFDBatchMove1.Name := '';
FFDBatchMove1.OnError := FDBatchMove1Error;
FFDBatchMove1.OnFindDestRecord := FDBatchMove1FindDestRecord;
FFDBatchMove1.OnProgress := FDBatchMove1Progress;
// FDBatchMoveDataSetReader1
FFDBatchMoveDataSetReader1 := TFDBatchMoveDataSetReader.Create(Self);
FFDBatchMoveDataSetReader1.Name := '';
// FDBatchMoveDataSetWriter1
FFDBatchMoveDataSetWriter1 := TFDBatchMoveDataSetWriter.Create(Self);
FFDBatchMoveDataSetWriter1.Name := '';
// FDBatchMove1
FFDBatchMove1.Reader := FFDBatchMoveDataSetReader1;
FFDBatchMove1.Writer := FFDBatchMoveDataSetWriter1;
FFDBatchMove1.Options := [poIdentityInsert];
FAccessDB.Params.Values['Database'] := 'database.accdb';
FAccessDB.Connected := True;
aDropTableSQL := 'DROP TABLE ' + FTablenameDest;
FAccessDB.ExecSQL(aDropTableSQL);
FAccessDB.Commit;
aCreateTableSQL := 'CREATE TABLE ' + FTablenameDest; // plus the rest
//of the create statement
FFDTable_Out.TableName := FTablenameDest;
FFDTable_Out.Active := True;
FFDBatchMoveDataSetReader1.DataSet := FDataSetSrc; // a TDataset from
// another database
FFDBatchMoveDataSetWriter1.DataSet := FFDTable_Out;
FFDBatchMoveDataSetWriter1.Direct := True;
FFDBatchMoveDataSetReader1.DataSet.Active := True;
FFDBatchMoveDataSetWriter1.DataSet.Active := True;
FFDBatchMove1.Mode := dmAlwaysInsert;
FFDBatchMove1.Execute;
FAccessDB.Commit;
FAccessDB.Connected := False;
FFDMSAccessService1 := TFDMSAccessService.Create(Self);
FFDMSAccessService1.Name := '';
FFDMSAccessService1.Database := 'database.accdb';
FFDMSAccessService1.DestDatabase := 'database.accdb_temp.accdb';
FFDMSAccessService1.DBVersion := avAccess2007;
FFDMSAccessService1.Compact; // <-- seems to convert here...
database.accdb的文件头变成
00 01 00 00 53 74 61 6E 64 61 72 64 20 4A 65 74 20 44 42 00 01 00 00 00 B5 6E 03 62 60 09 C2 55 E9 A9 67 72 40 3F 00 9C 7E 9F 90 FF 85 9A 31 C5
....Standard Jet DB.....µn.b`.ÂUé©gr@?.œ~Ÿ.ÿ…š1Å
同样,在从.mdb转换为.accdb之前
在我看来,“标准Jet DB”意味着旧格式(.mdb)
“标准ace db”表示新格式(.accdb)
firedac会把它转换回来吗?为什么?
如何保留新的访问格式(.accdb,ace db)?
最佳答案
刚收到Embarcadero的回复(非常快的回复,酷!)以下内容:
德米特里·阿雷菲耶夫写道:
这是一个众所周知的问题。目前,tfdmsaccessservice并不真正支持avaccess2007。
--
致以最诚挚的问候,
Dmitry Arefiev/Firedac建筑师
关于database - 带有MS Access 2010数据库的Delphi FireDAC。为什么将ACE转换为Jet?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33802277/