-3

I'm writing a VB NET program to read dBase .dbf files using the OleDbReader. When the filename contains an underscore, the OleDbDataReader gives a file not found error, whereas the same file without the underscore in the name works just fine.

Some sample code of what I'm doing:

    Dim dBaseConnection As OleDbConnection
    Dim dBaseCommand As OleDbCommand
    Dim dBaseDataReader As OleDbDataReader
    Dim schemaTable As DataTable
    Dim x, y, z

    Dim Builder As New OleDbConnectionStringBuilder With
        {
            .DataSource = IO.Path.GetDirectoryName(filename),
            .Provider = "Microsoft.Jet.OLEDB.4.0"
        }
    Builder.Add("Extended Properties", "dBase III")

    dBaseConnection = New OleDbConnection With {.ConnectionString = Builder.ConnectionString}
    dBaseConnection.Open()

    dBaseCommand = New OleDbCommand("SELECT * FROM " & filename, dBaseConnection)
    dBaseDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess)
    schemaTable = dBaseDataReader.GetSchemaTable()

        While dBaseDataReader.Read And Not _abort
            x = Val(dBaseDataReader("x").ToString)
            y = Val(dBaseDataReader("y").ToString)
            z = Val(dBaseDataReader("z").ToString)

            'do other stuff here
        End While

Does anyone know whether an underscore is a forbidden symbol for a dbf filename? Or is this some sort of bug?

In this case the filename was "c:\temp\test_info.dbf".

etri
  • 89
  • 8
  • Post some code of how you are reading/opening the .dbf file, this will let others better understand where your error may be as it may be spelling,grammar etc. which you just may of skipped over. Also some example file names would be useful. – K.Madden Jul 24 '19 at 11:02
  • Thanks @K.Madden for the suggestion. See above. – etri Jul 24 '19 at 15:48
  • What's the file name? Always safer to put the name in square brackets: [filename]. – LarsTech Jul 24 '19 at 15:49
  • @LarsTech: added this filename too. Thanks – etri Jul 24 '19 at 15:52
  • I can't reproduce the problem. A file name with an underscore works just as well, and I didn't change any of the relevant code. – LarsTech Jul 24 '19 at 16:07
  • @LarsTech That's really strange. I get the following error: System.Data.OleDb.OleDbException: 'The Microsoft Jet database engine could not find the object 'IWmeter_t.dbf'. Make sure the object exists and that you spell its name and the path name correctly.' Without the underscore (IWmeter.dbf) it works just fine. – etri Jul 24 '19 at 16:36
  • @LarsTech: to make it a bit stranger "IWmeter_.dbf" does work and "IWmeter_t.dbf" doesn't... – etri Jul 24 '19 at 16:42

1 Answers1

4

It is likely due to the filename (before extension) being> 8 characters in length. Back in the dBase days 8.3 was the max for any dbf file.

dsd7a7
  • 56
  • 1
  • 1
  • 2
  • So focused on the underscore that I didn't pay attention to the possibility that the filename length could be an issue... Thanks! – etri Jul 24 '19 at 18:25