Unable to Open .DBF Files in Windows 7 That Had Worked Under XP

wergeld picture wergeld · Dec 20, 2010 · Viewed 10.3k times · Source

I have a VB.NET application that will let me preview .DBF files that come in from some of our clients. The application then attempts to spit out a CSV from this file that we can then use in our various environments. This application worked under Windows XP 32 bit. Our company recently upgraded most of us to Windows 7 x64 which has caused this application to fail. I verified that the target build for this application is x86 and not "any CPU" and rebuilt the app but same issues occur.

It originally used System.Data.Odbc and connection.ConnectionString = "Driver={Microsoft dBASE VFP Driver (*.dbf)};SourceType = DBF;SourceDB=" & dbfSourcePath & ";Exclusive=No; Collate=Machine;BACKGROUNDFETCH=NO;". The location of the failure is at connection.Open(). The error given is: "ERROR [IM001] [Microsoft][ODBC Driver Manager] Driver does not support this function".

I noticed that the drivers for VFP were not installed and that the Access DBF drivers did not work similar to the post here. The fix listed there is to install VFPro SP2, however, we do not have any FoxPro installs to install a service pack on top of. I then tried to install the OLEDB driver for VFP 9.0 and am now using System.Data.OleDb and connection.ConnectionString = "Provider=VFPOLEDB.1;SourceDB=" & dbfSourcePath & ";" but it now tells me that the connection.Open() line has this error: "Feature is not available".

I am at a complete loss as to how to get this application to work under Windows 7 x64. Below are the 2 variants of the code with the file open path removed for readability (I have verified the path and file exist):

ODBC version:

Imports System.Data.Odbc
Dim strSelect As String
strSelect = "SELECT * FROM " & dbfSourceName
Dim connection As New Odbc.OdbcConnection
Dim adp As New Data.Odbc.OdbcDataAdapter
connection.ConnectionString = "Driver={Microsoft dBASE VFP Driver (*.dbf)};SourceType = DBF;SourceDB=" & dbfSourcePath & ";Exclusive=No; Collate=Machine;BACKGROUNDFETCH=NO;"
Dim command As New OdbcCommand(strSelect, connection)
connection.Open()          ' Here is where it throws the error.

OLEDB version:

Imports System.Data.OleDb
Dim strSelect As String
strSelect = "SELECT * FROM " & dbfSourceName
Dim connection As OleDbConnection = New OleDbConnection()
Dim adp As New Data.OleDb.OleDbDataAdapter
connection.ConnectionString = "Provider=VFPOLEDB.1;SourceDB=" & dbfSourcePath & ";"
Dim Command As New OleDbCommand(strSelect, connection)
connection.Open()          'Error occurs here.

How can I use either an OLEDB or ODBC connection to open these .DBF files under Windows 7 x64?

Answer

Chris Taylor picture Chris Taylor · Dec 20, 2010

Have you tried a few alternate connection strings? Take a look at www.connectionstrings.com/dbf-foxpro

connection.ConnectionString = _
  "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
  dbfSourcePath & ";Extended Properties=dBASE IV;"

Also see the note on using Jet for Access on 64 bit systems

Update: As an alternative to using the Jet driver, you can access the DBF directly, fortunately the file format is relatively simple. Here is an existing Code Project solution that demonstrates this direct access.

http://www.codeproject.com/KB/bugs/LoadDBF.aspx