Read a Visual FoxPro dbf file.

J

Joe

Hi all.

I'm trying to open a dbf file which appears to be FoxPro. I've tried using
the OLE and ODBC classes but I'm not having any luck.

I keep getting an exception: "The Microsoft Jet database engine could not
find the object 'EQR_TRANSACTION_200803'. Make sure the object exists and
that you spell its name and the path name correctly."

Here is the ODBC code:
try

{

string connString = @"DBQ=C:\Test;Driver={Microsoft dBase Driver (*.dbf)};
DriverId=277";


OdbcConnection conn = new OdbcConnection(connString);

OdbcDataAdapter da = new OdbcDataAdapter("select * from
EQR_TRANSACTION_200803", conn);

DataTable table = new DataTable("table");

da.Fill(table);

dataGridView1.DataSource = table;

}

catch (Exception e)

{

MessageBox.Show(e.Message);

}



Any ideas?



Thanks,

Joe
 
J

Jialiang Ge [MSFT]

Hello

I know some known scenarios where dBase Driver does not co-operate with
Foxpro well. We generally suggest customers using OLE DB Provider for Visual
FoxPro:
http://www.microsoft.com/downloads/...8f-2d58-491f-a0fa-95a3289c5fd4&displaylang=en

The sample connection strings based on Microsoft Visual FoxPro Driver can be
found at:
http://www.connectionstrings.com/?carrier=visualfoxpro

Bill, would you please try the Foxpro driver instead? If you have any
concerns about, please DON¡¯T hesitate to tell me.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

Joe

Using the connection string from the link below it seems to connect but I
get an error message Cannot open file c:\test\eqr.dbc.

What is a dbc file? I can open the dbf using a few programs I downloaded but
cannot open it in C#.
 
J

Jialiang Ge [MSFT]

Hello Joe,

¡°Dbc¡± is the file extension for Foxpro database; and ¡°dbf¡± is for tables
associated with the database. According to the error, it seems that you are
using the connection string:

Driver={Microsoft Visual FoxPro
Driver};SourceType=DBC;SourceDB=c:\myvfpdb.dbc;Exclusive=No;
NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO;

To connect to the database container (.dbc), and it fails to find the dbc?

Please try the connection strings for ¡°Free table directory¡±. The DBF
(free table) connection string only refers to the directory containing the
DBF, it does not specify a target table. All free tables within the
directory are then available for use in the recordset SQL statement.

You may also want to read Cindy Winegarden [Foxpro MVP]¡¯s comments in this
thread:
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic35499.aspx

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

Joe

Hello,

Here is the code I am running:
string connString = @"Provider=vfpoledb.1;Data Source=C:\test\;Collating
Sequence=general;";

OleDbConnection conn = new OleDbConnection(connString);

OleDbDataAdapter da = new OleDbDataAdapter("select * from
EQR_TRANSACTION_200803.dbf", conn);
DataTable table = new DataTable("table");
da.Fill(table);

The connString doesn't mention the dbc. Also I don't know where it even gets
the name of the dbc it is looking for.

-Joe

Jialiang Ge said:
Hello Joe,

¡°Dbc¡± is the file extension for Foxpro database; and ¡°dbf¡± is for
tables associated with the database. According to the error, it seems that
you are using the connection string:

Driver={Microsoft Visual FoxPro
Driver};SourceType=DBC;SourceDB=c:\myvfpdb.dbc;Exclusive=No;
NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO;

To connect to the database container (.dbc), and it fails to find the dbc?

Please try the connection strings for ¡°Free table directory¡±. The DBF
(free table) connection string only refers to the directory containing the
DBF, it does not specify a target table. All free tables within the
directory are then available for use in the recordset SQL statement.

You may also want to read Cindy Winegarden [Foxpro MVP]¡¯s comments in
this thread:
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic35499.aspx

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================

Joe said:
Using the connection string from the link below it seems to connect but I
get an error message Cannot open file c:\test\eqr.dbc.

What is a dbc file? I can open the dbf using a few programs I downloaded
but cannot open it in C#.
 
J

Jialiang Ge [MSFT]

Hello Joe,

As is mentioned in the quote of Cindy Winegarden [MVP]'s messages, there
are basically two types of tables (dbf).

1. Free table.
This type of table can be created by Foxpro->File menu->New->Table
It can exist without dbc files.

2. Table with a link to its database.
This type of table is created by Foxpro->File menu->New->Database (create a
dbc file)->New Table (create a dbf file)
If you move away dbc and open this type of dbf with foxpro, Foxpro pops up
an error message:
"C:\testdb\data1.dbc: The database for table 'C:\testdb\table1.dbf' could
not be opened. Would you like to try to locate the owning database or
delete the link (and free the table)."
By clicking the "Delete" button, the table will become a free table (of the
first type).

The error message "cannot open dbc" tells me that you are using a dbf file
of the second type. Please remove the link to dbc by the above-mentioned
method. Based on my own tests, your code snippet runs well as long as the
link is removed.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

Jialiang Ge [MSFT]

Hello Joe

I am writing to check the status of the issue on your side. Would you mind
letting me know the result of the suggestions? If you need further
assistance, feel free to let me know. I will be more than happy to be of
assistance.

Have a great day!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

Joe

I do not have FoxPro so I cannot do as you're suggesting. I tried a program
called DBF Viewer 2000 (http://www.dbf2002.com/) and this opens it fine.
I need a general solution for opening dbf files. I cannot rely on the end
user to have FoxPro and need to delete the link.

There has to be some other reason this doesn't work. Are there other
parameters that can be passed in the connection string that tells it not to
look for the dbc file?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top