问题
I've connected to foxpro databases before, but only ones that have both a .dbf and .idx file.
I register the Microsoft Ole DB Provider for Visual Foxpro 7.0 and use the following type of code:
string sqlSTR = "SELECT * FROM TableName";
string strConnect = @"Provider=VFPOLEDB.1;Data Source=C:\Stuff.dbf;Extended Properties=dBASE IV;"
And open the connection. This file, though, has a .dbf and .cdx file (which, reading online seems to be the structure of the database). When I use the connection string above and the following code:
OleDbConnection myConn = new OleDbConnection(strConnect);
myConn.Open()
It doesn't error or anything, but the execution of the program hangs here. I have several other parts of the same program that are connecting to files with a dbf + idx file present (not cdx). What am I doing wrong that I need to correct?
I use the sqlSTR for later operations using a data adapter btw.
回答1:
Posting this answer for anyone that has the same problem.
The reference for dBase IV actually doesn't matter either way; it does for the older DBF+IDX combination of foxpro files and is needed (think early VFP or before VFP back in foxpro 2.0 days).
All I was really missing was the *.dbc, *.dct, and *.dcx files in the same directory that were also associated with it. It threw me since these files were actually a different base filename than the Stuff.dbf/Stuff.cdx files.
I just used a try{}catch{} and put the exception to messagebox and it told me which (different named) file it was looking for.
Thanks for the help!
回答2:
Your connection string is wrong. It should be like:
string sqlSTR = "SELECT * FROM TableName";
string strConnect = @"Provider=VFPOLEDB;Data Source=C:\;"
Using c:\ as a location for database files (or other files) is questionable.
来源:https://stackoverflow.com/questions/44209231/c-sharp-vfp-oledb-connection-string-problems-dbf-and-cdx-vs-dbf-and-idx