Link to home
Start Free TrialLog in
Avatar of RobMinnis
RobMinnis

asked on

Reading dBase files with attached MDX via ADO.NET

I am trying to read and write dBase files via ADO.NET. The following code is able to open and read a dBase database if the MDX file is NOT present but always fails if the file is present.  I have tried numerous combinations of OLE DB, ODBC, drivers, providers, etc. that are part of the standard .NET package but none of them seem to able to work in the presence of the MDX files.

How does one work with indexed dBase files in ADO.NET?  [The documentation et al that I have found online suggests that the VFP driver is the most compliant when it comes to dBase formats.]

string path = @"valid db directory";
string cs = "Provider=VFPOLEDB.1;Data Source="+path+";Extended Properties=dBase 5.0";
OleDbConnection conn = new OleDbConnection(cs);
conn.Open();
string sql = @"SELECT * FROM DBFTABLE";
OleDbCommand cmd = new OleDbCommand(sql, conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds); // error occurs at this location - usually an "expected error" but varies somewhat with the driver, protocol, etc.  The code shown here produces a "is not a table" error if the MDX file is present.

I do not know the originating tool that created the DBF files (the files are part of a third party package).  Does anyone have the file format for the MDX files?  (maybe the MDX is in a non-standard or incorrect format - maybe I can determine the creating tool from the MDX format and/or find a workaround for the stadard tools)
Avatar of fjh_muc
fjh_muc

.MDX (multiple index) is usually only created and used by the original dBASE product.
There should be an ODBC driver available by DataDirect.

http://www.dbase.com/default.asp
Avatar of RobMinnis

ASKER

I had no luck with dBase (no ODBC or OLEDB driver that I could find and no response from their tech support).  However, I was able to use CodeBase.  They claim to have an ODBC driver but it is part of the more expensive package.  So, for this project, I'm using their proprietary API.
Moderator:  How do I end this question without accepting a solution?
Rob you might try using DAO to open the dbf then convert the data types to ADO.
The problem is that ADO doesn't know how to handle the data types in the dbf. I once solved this problem with a legacy dBase / Clipper application that we rewrote in vb6 using ADO.
If it is an older dbf, which the MDX indicates, this will probably work. The MDX file is an index and won't affect the content of the data in the dbf.
ASKER CERTIFIED SOLUTION
Avatar of pcurtis_expert
pcurtis_expert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial