We need to connect/read/write to FoxPro database via C# and facing an issue with that.
From our understanding there are three different ways to connect to FoxPro database - Ole Driver, ODBC Driver and VFPOLE Driver.
Visual FoxPro ODBC Driver: as per article on this page https://learn.microsoft.com/en-us/previous-versions/visualstudio/foxpro/mt490121(v=msdn.10) the VFPODBC drive is no more supported and is recommended to use Visual FoxPro OLE DB.
Visual FoxPro Ole Driver: when running on windows x86, we face issue that 'VFPOLEDB' provider is not registered on the local machine. (FYI-The vfpoledb.dll exists at C:\Program Files (x86)\Common Files\System\Ole DB). To our knowledge, it is giving issue as VFPOLEDB driver works on 32-bit machine instead od 64-bit machine.
Access Manager OLE Driver: able to connect to the database, but unable to read the table and gives issue External table is not in the expected format, seems because we are using dBase IV when establishing connection.
Looking forward to immediate help on this.
This is the code snippet:
static void Main(string\[\] args)
{
OleDbConnection conn = null;
try
{
// Option 1.1) Free table directory - ACE OLE
conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\AutoParts\\db;Extended Properties=dBase IV;");
// Option 1.2) Free table directory - VFPOLE
// conn = new OleDbConnection("Provider=VFPOLEDB;DRIVER=Microsoft Visual FoxPro Driver;Data Source=D:\\AutoParts\\db;Collating Sequence=machine;");
// Option 2.1) Database Container - ACE OLE
// conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\AutoParts\\db2;Extended Properties=dBase IV;");
// Option 2.2) Database Container - VFPOLE
// conn = new OleDbConnection("Provider=VFPOLEDB;DRIVER=Microsoft Visual FoxPro Driver;Data Source=D:\\AutoParts\\db2;Collating Sequence=machine;");
conn.Open();
Console.WriteLine(conn);
string strQuery = "Select \* from Employee.dbf";
OleDbCommand myQuery = new OleDbCommand(strQuery, conn);
OleDbDataAdapter DA = new OleDbDataAdapter(myQuery);
Console.WriteLine(DA);
using (var reader = myQuery.ExecuteReader())
{
while (reader.Read())
{
var str = (string)reader\["empl_id"\];
Console.WriteLine(str);
}
}
}
finally
{
conn.Close();
}
}