Search code examples
c#oledbvisual-foxpro

File 'phd.prg' does not exists


I have a visual fox pro 9 database, and i am trying to connect it from my desktop application.

i can get data from almost all tables except one table.

when i run query to select data from "test.dbf" it throws exception saying

File 'phd.prg' does not exists

i am using VFP OLEDB drivers to connect with database.

 DataTable YourResultSet = new DataTable();
        OleDbConnection yourConnectionHandler = new OleDbConnection(
               "Provider=VFPOLEDB.1;Data Source=E:/TRACKONE.DBC;Exclusive=false;Nulls=false;");
        yourConnectionHandler.Open();

        if (yourConnectionHandler.State == ConnectionState.Open)
        {
            OleDbDataAdapter DA = new OleDbDataAdapter();

            string mySQL = "SELECT * FROM TEST.DBF";
            OleDbCommand MyQuery = new OleDbCommand(mySQL, yourConnectionHandler);


            DA.SelectCommand = MyQuery;
            try
            {
                DA.Fill(YourResultSet);

            }
            catch (OleDbException ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            yourConnectionHandler.Close();
            return YourResultSet;

        }

        else
        {
            MessageBox.Show("Error Opening Databse");
        }

        return null;

Solution

  • I Got it working finally, it seems there was problem with new oledb driver, so i am using ODBC driver "Microsoft Visual FoxPro Driver" now. it was hard to find but after alot of search i found this driver here.VFODBC

    public DataTable GetYourData2(string textquery)
            {
                using (OdbcConnection conn = new OdbcConnection("Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;Exclusive=No;Collate=Machine;NULL=NO;DELETED=YES;BACKGROUNDFETCH=NO;SourceDB=e:/"))
                    {
    
    
                    OdbcDataAdapter ODA = new OdbcDataAdapter();
    
                    OdbcCommand ODC = new OdbcCommand(textquery, conn);
                    ODA.SelectCommand = ODC;  
                    conn.Open();
                    ODA.Fill(YourResultSet);
    
                    return YourResultSet;   
                }
    
    
        }
    

    Thanks for your support.