我已按照以下步骤将 .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 / TFDPhysMSAccessDriverLink / 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 之前也是如此
在我看来,“Standard Jet DB”意味着旧格式(.mdb) 'Standard ACE DB' 表示新格式 (.accdb)
FireDAC 会将其转换回来吗?为什么? 如何保留新的 Access 格式(.accdb、ACE DB)?
刚刚收到Embarcadero的答复:
德米特里·阿雷菲耶夫写道:
这是一个已知问题。目前 TFDMSAccessService 并不真正支持 avAccess2007。