解决ERROR [42S02] [Microsoft][ODBC Visual FoxPro Driver]File 'xxx.dbf' does not exist.
的问题:
是因为连接FoxPro的连接字符串存在问题
"Driver={Microsoft Visual FoxPro
Driver};SourceType=DBF;SourceDB=c:/TestTzm/Test.dbf";Exclusive=No;BackgroundFetch=No;";
这个连接串是错误的.
在访问的时候,连接会自动查找路径下的dbf文件或者创建dbf文件,所以不需要dbf文件
正确的连接如下:
"Driver={Microsoft Visual FoxPro
Driver};SourceType=DBF;SourceDB=c:/TestTzm";Exclusive=No;BackgroundFetch=No;";
注意SourceDB=c:/TestTzm,这里只要写路径就可以了,不需要添加Test.dbf文件
procedure TForm1.Button1Click(Sender: TObject);
var
db_file_tmp:string;
begin
db_file_tmp := 'C:\Users\xy\Desktop\38扫描数据201104271024-2\';
ADOConnection1.Close;
ADOConnection1.ConnectionString:='Provider=MSDASQL.1;Persist Security Info=False;Extended Properties="Driver={Microsoft FoxPro VFP Driver (*.dbf)};UID=;'
+'SourceDB='+db_file_tmp+';SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;"';
ADOConnection1.LoginPrompt := False;
try
try
ADOConnection1.connected := true;
except on E: Exception do
begin
showmessage('数据库连接失败,原因:' + #13#10 + E.Message);
abort;
end;
end;
finally
;
end;
//
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'select * from kddzb.dbf' ;
ADOQuery1.Open;
ADOQuery1.First;
ShowMessage(inttostr(ADOQuery1.recordcount));
end;