我必须使用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])
答案 0 :(得分:4)
我认为使用TADOConnection的CursorLocation
的默认设置为clUseClient
。使用该设置,客户端将整个数据集读入内存。这可以解释缓慢并可以解释错误。
尝试将其更改为clUseServer
。
ADOConn.CursorLocation := clUseServer;
或者您可以在对象检查器属性中更改它。
答案 1 :(得分:4)
这听起来好像它在头文件中有一个autoopen(.MDX)索引标志,但索引在数据库中不存在。
你可以尝试这个 - 它清除数据库头中的autoopen标志。 使用数据库的副本进行测试!!! 我没有在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;
在标题中清除该标志后,您应该能够使用ADO或Advantage Database Server打开.DBF - 它们的本地服务器是免费的,并且支持SQL。请注意,我不以任何方式与Advantage有关联;我已经使用他们的产品长期使用旧版DBF文件了。
答案 2 :(得分:-1)
如果您仍然遇到TAdoConnection问题,我建议Apollo。这支持许多不同的表类型(Clipper NTX,Foxpro CDX)。