I had a problem opening a DBF file - I need to open it, read everything and process it. I tried several solutions (ODBC / OLEDB), several connection strings, but so far nothing has worked.
The problem is that when I execute the SQL command to get everything from the file, nothing is returned - there are no rows. Even stranger, the contents of the opened DBF file are deleted.
See the code I have:
public override bool OpenFile(string fileName, string subFileName = "") { OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(fileName) + ";Extended Properties=dBASE IV;User ID=;Password=;"); try { if (con.State == ConnectionState.Closed) { con.Open(); } OleDbDataAdapter da = new OleDbDataAdapter("select * from " + Path.GetFileName(fileName), con); DataSet ds = new DataSet(); da.Fill(ds); con.Close(); int i = ds.Tables[0].Rows.Count; return true; } catch { return false; } }
I debugged the code and watched the file open in Windows Explorer. When it reaches this line:
da.Fill(ds);
file size dropped to a few bytes (from hundreds of kB).
My next thought was to make the DBF file read-only. This nonetheless raises an "unexpected exception from the external driver."
So my question is what the hell? I am sure that the file is not corrupted, this is a direct export from some kind of database. (No, I do not have access to this database). I can also open this file in MS Office without problems.
I can not share the DBF file - it contains sensitive data.
source share