连接VFOXPRO的字符串该用那个?来看下我这里奇怪的现象~~~顶者有分~~
下面的连接都会出同样的问题
运行select * from psw.dbf 运行成功
运行select * from ysxs.dbf 就会提示,外部数据库驱动(8961)中意外错误
关了打开,无论扎样,除了能查询PSW。DBF表之外,其他运行就报这个错误,难道其他表有什么不同吗?还是什么原因,那位帮忙下。
以下是我连接用的三个字符串都还是有问题。
con1.ConnectionString:= 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= ' +extractfilepath(
application.ExeName)+ ';Extended Properties=dBASE 5.0;User ID=Admin;Password= ';
{con1.ConnectionString:= 'Provider=Microsoft.Jet.OLEDB.4.0 '+ ';Data Source= '+extractfilepath(application.ExeName)+ ';Extended Properties=dBase III;Persist Security Info=False ';
}
{con1.ConnectionString:= 'Provider=MSDASQL.1;Connect Timeout=15;Extended '
+ 'Properties=;DefaultDir= '+extractfilepath(
application.ExeName)+ ';Deleted= '+
'1;Driver={Microsoft dBase Driver (*.dbf)};DriverId=533;FIL=dBase '+
'5.0;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=600;SafeTransactions= '+
'0;Statistics=0;Threads=3;UID=admin;UserCommitSync=Yes; ";Locale Identifier= ' +
'2052 '; }
[解决办法]
Delphi用ADO连接VFP数据库或数据表
以下是试验成功的动态连接.DBF表的句子:
1、ADOQuery
ADOQuery1.SQL.Text := 'select * from dbf文件名.dbf ';
ADOQuery1.ConnectionString := 'Provider=MSDASQL.1;Extended Properties= "Driver={Microsoft Visual Foxpro Driver};SourceType=DBF;SourceDB=c:\ " '; //注意,C:\是指DBF文件所在目录,下同
ADOQuery1.Open;
2、ADOTable
ADOTable1.ConnectionString := 'Provider=MSDASQL.1;Extended Properties= "Driver={Microsoft Visual Foxpro Driver};SourceType=DBF;SourceDB=c:\ " ';
ADOTable1.TableName := 'dat.dbf ';//dat.dbf为DBF文件名,下同
ADOTable1.Open;
3、ADOConnection + ADOQuery
ADOConnection1.ConnectionString := 'Provider=MSDASQL.1;Extended Properties= "Driver={Microsoft Visual Foxpro Driver};SourceType=DBF;SourceDB=c:\ " ';
ADOConnection1.LoginPrompt := false;
ADOConnection1.CursorLocation := clUseServer;//这句似乎不是必须的
ADOConnection1.Open;
ADOQuery1.Connection := ADOConnection1;
ADOQuery1.SQL.Text := 'select * from dat.dbf ';
ADOQuery1.Open;
4、ADOConnection + ADOTable
ADOConnection1.ConnectionString := 'Provider=MSDASQL.1;Extended Properties= "Driver={Microsoft Visual Foxpro Driver};SourceType=DBF;SourceDB=c:\ " ';
ADOConnection1.LoginPrompt := false;
ADOConnection1.CursorLocation := clUseServer;//这句似乎不是必须的
ADOConnection1.Open;
ADOTable1.TableName := 'dat.dbf ';
ADOTable1.Connection := ADOConnection1;
ADOTable1.Open;
--------------------------------------
以下是一篇参考文章:
连接DBF数据
构造ado connection string
提供者选择 Microsoft Jet 4.0 OLEDB Provider
"所有 "那里编辑 Extended Properties,
dbf文件的话设置为dBase 5.0(注意dBase和5.0之间必须有空格,最好拷贝过去粘贴)
db文件的话设置为Paradox 7.X
(dbf就是dbase或Vfox数据库,db就是paradox数据库)
“连接”那里的“数据库名称”输入的是目录名,不能包含文件名,
比如你的文件是 c:\temp\aaa.dbf ,那么输入c:\temp
同时CursorLocation 设置为: clUseServer
还可以:
如果直接连的话,ADO的连接字串设为:
adoConnection1.ConnectionString:= 'Provider=MSDASQL.1;Extended Properties= "Driver={Microsoft Visual Foxpro Driver};SourceType=DBF;SourceDB=c:\mydb " ';
如果是用ODBC,先在ODBC中设一个DSN连接到该DBF库,然后,在ADOConnection中设置连接ODBC的连接字串即可(可以用向导帮助完成)