?
Solved

Reading dBase 3 and dBase 4 files with nonstandard extensions in C#

Posted on 2008-10-09
10
Medium Priority
?
4,037 Views
Last Modified: 2013-12-17
Hi. I have been using the FoxPro ODBC driver to open dBase3 files with nonstandard extensions and it works just fine. However, when I try to open a dBaseIV file I get the error "ERROR [42S02] [Microsoft][ODBC Visual FoxPro Driver]Not a table."

I have tried FoxPro OleDB driver, but apparently the files have to be named with a ".dbc" extension.

Is there anyway I can use a single driver to open these dBase 3 and dBase 4 files that have nonstandard extensions?

Below is the code I am using. And I have attached one of the files I am having issues with if anyone wants to see if they can open and read it. I had to change the extension to .txt to get it to upload, but you can change it to .veh or whatever you like.

Thanks.
string tagNum = "";
            OdbcConnection oConnection = new OdbcConnection("Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\\Documents and Settings\\Lee\\Desktop\\Mitchell EMS;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;");
            oConnection.Open();
 
 
            OdbcDataAdapter oDataAdapter = new OdbcDataAdapter("SELECT * FROM 123A.ad1", oConnection);
            DataSet oDataSet = new DataSet();
            oDataAdapter.Fill(oDataSet);//I get the error right here...
            DataTable oDataTable = oDataSet.Tables[0];
            foreach (DataRow dr in oDataTable.Rows)
            {
 
 
                tagNum = (dr["PLATE_NO"].ToString().Trim());
              
 
            }//end foreach

Open in new window

dBaseFile.zip
0
Comment
Question by:TongueNGroove
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 

Author Comment

by:TongueNGroove
ID: 22683685
If I try to open the file using oleDB from fox pro i get the error "File must be opened exclusively to convert the Memo file."
string tagNum = "";
            OleDbConnection oConnection = new OleDbConnection("Provider=vfpoledb.1;Data Source=C:\\Documents and Settings\\Lee\\Desktop\\Mitchell EMS\\;Exclusive=Yes;Collating Sequence=machine;");
            oConnection.Open();
 
 
            OleDbDataAdapter oDataAdapter = new OleDbDataAdapter("SELECT * FROM 123A.ad1", oConnection);
            DataSet oDataSet = new DataSet();
            oDataAdapter.Fill(oDataSet);//I get the error right here...
            DataTable oDataTable = oDataSet.Tables[0];
            foreach (DataRow dr in oDataTable.Rows)
            {
 
 
                tagNum = (dr["PLATE_NO"].ToString().Trim());
              
 
            }//end foreach

Open in new window

0
 
LVL 6

Expert Comment

by:carlsiy
ID: 22683786
try changing the connection string

I am using this to open dbase III and dbase IV files in c#

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder;Extended Properties=dBASE IV;User ID=Admin;Password=;
0
 

Author Comment

by:TongueNGroove
ID: 22683970
The problem with that is, the files have to have a standard .dbf extension. The files I am using have different extensions.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 20

Expert Comment

by:ElrondCT
ID: 22689621
So why not just rename the file before opening, then rename back when you're done?
0
 

Author Comment

by:TongueNGroove
ID: 22690552
I can't rename the files because other systems may be accessing them at the same time and that would cause a lot of issues.

What I need is a driver and connection string that allows me to open dBase3 and dBase4 files with nonstandard extensions.

I have a program called dbase viewer that will open all of these files in a GUI, so I know it's possible. But  I have no idea how the program is doing it.
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 2000 total points
ID: 22690780
A specialized application like dBase Viewer may well be doing direct data access on a byte-by-byte basis, rather than using a standard driver. The dBase data structure is published, and is really pretty simple, so it's not an overly difficult project to do (particularly if you don't have memo files that you have to read). Obviously, not as easy as using a standard driver, but I don't know how much flexibility you'll find with them.

I found code to do that at CodeProject: http://www.codeproject.com/KB/bugs/LoadDBF.aspx. I can't vouch for it, but it looks like it might meet your needs. The author specifically mentions that it's useful for those for whom the standard Jet and FoxPro drivers aren't workable.
0
 

Author Comment

by:TongueNGroove
ID: 22692462
Thanks for link. It does look interesting, but a bit too complex and unwieldy and I am not even sure it would be worth the trouble to try to figure out since it may not work correctly anyway.
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 22692589
You know what complexity you can handle, but I think you're overly pessimistic about the quality of what's offered; I've generally had very good results with stuff from Code Project, and as I said, the dBase file structure isn't overly difficult to process; it was designed in the early days of computing, when computers didn't have as much horsepower and developers weren't tempted to put as many bells and whistles into their systems. The article has been well rated by people using it. Note that there's a download of the actual class file; you're not expected to cut and paste from the web page.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question