Najem
Najem

Reputation: 557

open a dBase table

I have to copy some information from an old dBase database using ADOConnection and AdoTable. I am able to open all tables but I get this exception

Data provider or other service returned an E_FAIL status

while trying to open a big table 1.01 GB (1 093 588 624 bytes). I note that the performance is very bad. this is the connection string

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

Upvotes: 2

Views: 2647

Answers (3)

Ken White
Ken White

Reputation: 125671

This sounds like it's got an autoopen (.MDX) index flag in the header, but the index doesn't exist in the database.

You can try this - it clears that autoopen flag in the database header. USE A COPY OF THE DATABASE TO TEST ON!!! I haven't tested on DBase IV, but it works on several flavors of FoxPro and 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.

Upvotes: 4

M Schenkel
M Schenkel

Reputation: 6364

If you still have problems with TAdoConnection I would suggest Apollo. This supports many different table types (Clipper NTX, Foxpro CDX).

Upvotes: -1

Mark Wilkins
Mark Wilkins

Reputation: 41222

I believe that the default setting for CursorLocation with TADOConnection is clUseClient. With that setting, the entire data set is read into memory by the client. That would explain the slowness and may explain the error.

Try changing it to clUseServer.

ADOConn.CursorLocation := clUseServer;

Or you can change it in the object inspector properties.

Upvotes: 6

Related Questions