Gali Gali - 4 months ago 92
C# Question

how to connect to dbf database

I try to connect to DBF database using C# (I try 3 types of connection)

string connectionString = @"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\employees.dbf;";
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\employees.dbf;Extended Properties=dBASE IV;";
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\employees.dbf;Extended Properties=dBASE IV;User ID=Admin;Password=;";

using (OdbcConnection connection = new OdbcConnection(connectionString))
{
connection.Open();
}


and I got error

error1:


ERROR [HY024] [Microsoft][ODBC dBase Driver] '(unknown)' is not a
valid path. Make sure that the path name is spelled correctly and
that you are connected to the server on which the file resides.

ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's
SQLSetConnectAttr failed

ERROR [HY024] [Microsoft][ODBC dBase Driver] '(unknown)' is not a
valid path. Make sure that the path name is spelled correctly and
that you are connected to the server on which the file resides.


or error2:


ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name
not found and no default driver specified


what can be the problem ?

thanks in advance

Answer
Dim Conn As New OLEDBConnection  
Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder;Extended Properties=dBASE IV;User ID=Admin;Password=;"

To select from the database tables you must do the following (for instance):

"SELECT * FROM tblCustomers.DBF"

(Note the .DBF after the table name)