You are currently offline, waiting for your internet to reconnect

Error message "Cannot open file <path>\xxx.DBC" reading Microsoft Visual FoxPro tables via the VFP OLE DB Provider

Source: Microsoft Support
RAPID PUBLISHING
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Action
You are using the Visual FoxPro (VFP) OLE DB Provider to read data from VFP tables (.DBF) files.
Result
You receive an error message "Cannot open file <path>\xxx.DBC"
Cause
VFP table files can exist as free tables or as members of a VFP database container (.DBC). If you do not have the VFP database container files (.DBC, .DCT, .DCX) required by the table (.DBF), you will receive this error message.
Resolution


The best resolution for this problem is to get the database files required. If they are unavailable however, you can use VFP itself to free the table from the database container. If you do not have VFP, you can use VFP code executed through the VFP OLE DB Provider to free the table.

Following is sample code demonstrating how to free a VFP table from a database container using Microsoft Visual Studio C# and the VFP OLE DB Provider:



private void button1_Click(object sender, EventArgs e)
        {
            string dataDIR = System.Environment.CurrentDirectory + "\\VFPDATA\\";
            // Function to clear DBC membership from DBF
            FreeFoxTable(dataDIR + "DBCDBF.dbf");
            try
            {
                string connString = @"Provider=vfpoledb.1;Data Source=" + dataDIR;
                OleDbConnection conn = new OleDbConnection(connString);
                conn.Open();
                OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM DBCDBF", conn);
                DataTable table = new DataTable("table");
                da.Fill(table);
                dataGridView1.DataSource = table;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
           
        }
       



        private void FreeFoxTable(string cTableName)
        {
            string dataDIR = Path.GetDirectoryName(cTableName);
            string connString = @"Provider=vfpoledb.1;Data Source=" + dataDIR;
            string CDXFile = Path.ChangeExtension(cTableName, "CDX");
            OleDbConnection conn = new OleDbConnection(connString);
            OleDbCommand cmd = new OleDbCommand("EXECS([USE " + cTableName + "])", conn);
            conn.Open();
           
            try
            {
                // Use the table. If it's a member of a (missing) DBC we get
                // an error cannot open file .... <something>.dbc
                cmd.ExecuteNonQuery();
            }
            catch (Exception err)
            {
                if (err.Message.ToLower().Contains("cannot open file") && err.Message.ToLower().Contains("dbc"))
                {
                    // Free the DBF from the DBC container.
                    // We use the FoxPro command "FREE TABLE" to do this
                    // and execute it through the VFP OLE DB Provider
                    // usign the FoxPro EXECS() function.
                    cmd.CommandText = "EXECS([FREE TABLE " + cTableName + "])";
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    conn.Dispose();
                    cmd.Dispose();
                }
            }
           
            // Delete any index file that may be associated with the table being checked.
            // This prevents a "variable not found" error opening the table if there happens
            // to be an index expression that uses long field names which may be no longer
            // valid since we removed the DBF from the DBC.
            if (File.Exists(CDXFile)){
                File.Delete(CDXFile);
            }
        } 
More Information
DISCLAIMER
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
Properties

Article ID: 956244 - Last Review: 07/25/2008 19:42:42 - Revision: 1.1

Microsoft Visual FoxPro 9.0 Professional Edition

  • kbnomt kbrapidpub KB956244
Feedback
\xxx.DBC" " />
\xxx.DBC" " />
var varCustomerTracking = 1; var Route = "76500"; var Ctrl = ""; document.write(" html>e}}" href="" ng-click="setLanguage(language);" class="ng-binding" id="language-es-py">Paraguay - Español
Venezuela - Español
/html>microsoft.com/c.gif?DI=4050&did=1&t="> var varCustomerTracking = 1; var Route = "76500"; var Ctrl = ""; document.write(" ')[0].appendChild(m);" onload="var m=document.createElement('meta');m.name='ms.dqp0';m.content='false';document.getElementsByTagName('head')[0].appendChild(m);" src="http://c1.microsoft.com/c.gif?"> >>