I'm trying to connect to a Visual FoxPro Database that I downloaded for testing purposees using OLE DB, this is my code:
private void ReadMyData() {
String dbProvider = "Provider=.NET Framework Data Provider for OLE DB;";
String dbSource = "Data Source=VFPOLEDB.C:\\USERS\\X\\DESKTOP\\LOG;";
String connectionString = dbProvider + dbSource;
OleDbConnection FPDBConn = new OleDbConnection(connectionString);
OleDbCommand FPDBCmd;
string sql = null;
sql = "Select * from clogbook";
try {
FPDBConn.Open();
FPDBCmd = new OleDbCommand(sql, FPDBConn);
OleDbDataReader FPDBReader = FPDBCmd.ExecuteReader();
while (FPDBReader.Read()) {
Debug.Write(FPDBReader.GetInt32(0) + ", " + FPDBReader.GetString(1));
}
FPDBReader.Close();
FPDBCmd.Dispose();
FPDBConn.Close();
} catch (Exception ex)
{
Debug.Write("Can not open connection ! " + ex);
}
}
The problem is I'm getting "System.InvalidOperationException: The '.NET Framework Data Provider for OLE DB' provider is not registered on the local machine."
I was googling about it and came across this msdn page that says that the exception "InvalidOperationException" has the condition "The connection is already open." Which I don't think is happenning in this case.
How can I get this to work?
PS: Accepting different suggestions to make this connection.
For connecting to VFP, I would strongly suggest and download the Visual Foxpro OleDb Provider.
Then, the connection string would be formatted something like...
string connectionString = @"Provider=VFPOLEDB.1;Data Source=C:\YourDirectory\";
The connection should point to the PATH where the tables are located as you currently have... many times people try to connect to the specific TABLE, but once the path is established, you can query from ANY table that is in that folder (or child folder if so available).
Should get you a bit further...