4
votes

We need to read data from FoxPro 8 with C#. I'm gonna do some operations, and will push some of thoses data to an SQL Server database. We are not sure what's best method to read those data.

I saw OLE DB and ODBC; what's best?

REQUIRMENTS:

  1. The export program will run each night, but my company runs 24h a day.
  2. The DBF could sometimes be huge.
  3. We DON'T need to modify data.
  4. Our system, wich use FoxPro, is quite unstable: I need to find a way that ABSOLUTELY do not corrupt data, and, ideally, do not lock DBF files while reading.
  5. Speed is a minor requirement: it must be quick, but requirement #4 is most important.
4
+1 for still having to deal with FoxPro DBFs just like me :) - Tim B James
VFP ODBC has been deprecated for several years now. - pmoleri

4 Answers

5
votes

I would use the OLEDB connector - it has been updated much more recently, is faster and handles memory better.

If you are just reading data from the DBF via the OLEDB driver, I wouldn't worry about locking at record or file level, or corrupting data. All you need to do is handle exceptions in your C# code, for example when some process in your FoxPro application has the DBF open exclusively and you can't read it.

You also need to be careful that any queries are optimised to use available indexes on the DBF file, especially since you mention that it's large.

I assume this is all on the same LAN? If it has to work across the internet then you need to investigate exposing the FoxPro data via a web service.

Finally, there are other options for accessing DBF files.

Sybase also provide ODBC and OLEDB drivers that can access DBF files - however they cannot use FoxPro triggers, stored procedures and so on. That almost certainly doesn't matter in your case, though.

2
votes

According to this MSDN article, it suggests using the Visual FoxPro OLE DB Provider. Look at the article and it gives examples on how to to use the OLE DB provider and how to query data from the DBF data source.

0
votes

It's also quite easy to write some code in VFP that will dump the data to CSV or XML - consider adding this code to your FoxPro application. Processing these files could be much easier than trying to connect to a flaky FoxPro database.

0
votes

There is a LinqToVfp tool on Codeplex. See: http://linqtovfp.codeplex.com

It has some nice samples that will help get you started.