Search code examples
c#oledb

C# : Connecting to dbf file using Microsoft.ACE.OLEDB.12.0


I am trying connect to dbf file in 64 bit os using Microsoft.ACE.OLEDB.12.0 provider.

I wrote

   [Test]
    public void CustomDbfReader()
    {
        string filepath = @"K:\data";

        var dataTable = new DataTable();

        string connectionString =
            "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=dBASE IV;Data Source='" + filepath +"'" ;

        using (var oledbConnection = new OleDbConnection(connectionString))
        {
            oledbConnection.Open();
            string stringCommadn = string.Format(@"select * from filename.dbf");
            var oleDbCommand = new OleDbCommand(stringCommadn, oledbConnection);
            var oleDbDataAdapter = new OleDbDataAdapter
                                       {
                                           SelectCommand = oleDbCommand
                                       };
            oleDbDataAdapter.Fill(dataTable);
        }
        Assert.IsNotEmpty(dataTable.Rows);
    }

I get this exception

System.Data.OleDb.OleDbException : The Microsoft Access database engine could not find the object 'CardifOrigin.dbf'. Make sure the object exists and that you spell its name and the path name correctly. If 'CardifOrigin.dbf' is not a local object, check your network connection or contact the server administrator.

I am sure both path and file name exist.

What's the problem?


Solution

  • The dbase rules for names force a max of 10 characters. In Approach, information about longer names is stored in a special index that Microsoft doesn't know about.

    The 12 character one is the one that doesn't work. If you rename it to 8 characters, then it works fine.

    The Microsoft Jet database engine could not find the object filename

    In Microsoft Access, when you import a dBase, FoxPro, or Paradox file that does not follow the MS-DOS 8.3 file name format (that is, its name before the period exceeds eight characters, or it lacks a three-character extension following the period), you may receive the following error message:

    The Microsoft Jet database engine could not find the object filename. Make sure the object exists and that you spell its name and the path name correctly.