Does ODBC not support reading DBF file?

3

I'm trying to read a .dbf file by following a tutorial I saw on Macoratti's website (obs guess everyone knows). And when you run the method just below, a OdbcException is thrown with the following message: ERROR [IM001] [Microsoft][ODBC Driver Manager] O driver não oferece suporte para esta função

        private DataTable lerDbf(string filename)
        {
            using (OdbcConnection conn = new OdbcConnection("Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" +
                                         System.IO.Path.GetFullPath(filename).Replace(System.IO.Path.GetFileName(filename), "") + ";Exclusive=No"))
            {
                string consulta = "SELECT * FROM [" + System.IO.Path.GetFileName(filename) + "]";
                OdbcDataAdapter adapter = new OdbcDataAdapter(consulta, conn);
                DataSet ds = new DataSet();
                adapter.Fill(ds);
                return ds.Tables[0];
            }
        }

Regarding the tutorial and the files, it says:

  

[...] just select the default FoxPro Dbase file and import ...

The .dbf files I have to read on the system are generated from .xls . Is this the problem? What happens? Is there something in the code, maybe in the connection string that is wrong?

    
asked by anonymous 26.06.2014 / 17:22

1 answer

2

In this case the problem was really in the connection string. In this OS question - link - correctly.

string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourfilepath;Extended Properties=dBASE IV;User ID=Admin;Password=;";
using (OleDbConnection con = new OleDbConnection(constr))
            {
                var sql = "select * from " + fileName;
                OleDbCommand cmd = new OleDbCommand(sql, con);
                con.Open();
                DataSet ds = new DataSet(); ;
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                da.Fill(ds);
            }
    
26.06.2014 / 18:14