2

我必须使用 ADOConnection 和 AdoTable 从旧的 dBase 数据库中复制一些信息。我能够打开所有表格,但我得到了这个例外

数据提供者或其他服务返回 E_FAIL 状态

在尝试打开一个 1.01 GB(1 093 588 624 字节)的大表时。我注意到性能非常糟糕。这是连接字符串

  ConnectionString:=Format('Provider=Microsoft.JET.OLEDB.4.0;Data Source=%s;Extended Properties=dBase IV;',[path])
4

3 回答 3

5

我相信CursorLocationTADOConnection 的默认设置是clUseClient. 使用该设置,客户端会将整个数据集读入内存。这将解释缓慢并可能解释错误。

尝试将其更改为clUseServer.

ADOConn.CursorLocation := clUseServer;

或者您可以在对象检查器属性中更改它。

于 2011-03-24T14:41:03.673 回答
4

这听起来像是在标头中有一个自动打开 (.MDX) 索引标志,但该索引在数据库中不存在。

你可以试试这个——它会清除数据库标题中的自动打开标志。使用数据库的副本进行测试!!!我没有在 DBase IV 上进行过测试,但它适用于 FoxPro 和 DBase 的多种版本。

procedure FixDBFHeader(const FileName: string);
var
  ByteRead: Byte;
  Stream: TFileStream;
begin
  Stream := TFileStream.Create(FileName, fmOpenReadWrite or fmShareDenyNone);
  try
    // Byte offset 28 has a value of 0x01 if a structural (auto-open) index exists,
    // or 0x00 if no such index exists. If the value is not set, we do nothing.
    Stream.Position := 28;
    Stream.Read(ByteRead, SizeOf(ByteRead));
    if ByteRead = 1 then
    begin
      ByteRead := 0;
      Stream.Position := 28;
      Stream.Write(ByteRead, SizeOf(Byte));
    end;
  finally
    Stream.Free;
  end;
end;

After clearing that flag in the header, you should be able to open the .DBF with ADO or Advantage Database Server - their local server is free, and supports SQL. Note that I'm not affiliated with Advantage in any way; I've just used their product to work with legacy DBF files for a long time.

于 2011-03-24T15:02:24.080 回答
-1

如果您对 TAdoConnection 仍有问题,我建议您使用Apollo。这支持许多不同的表类型(Clipper NTX、Foxpro CDX)。

于 2011-03-24T14:56:48.780 回答