How to read dbase file and apply different decoding?

I have a dbf file encoded as 866 (DOS) codepage

Using the code below, I am trying to read it. The problem is that the lines that I get are formed as if the file was on code page 1252. I have not yet checked other issues in SO and other forums. Looking for hot ideas to read this.

var ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PathtoFile\;Extended Properties=""dBase 5.0"""; var dBaseConnection = new System.Data.OleDb.OleDbConnection(ConnectionString ); dBaseConnection.Open(); var dBaseCommand = new System.Data.OleDb.OleDbCommand("SELECT * FROM FileName",dBaseConnection); var dBaseDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess); while( dBaseDataReader.Read()){ Encoding.GetEncoding(866).GetString(Encoding.GetEncoding(1252).GetBytes(dBaseDataReader.GetString(2)).Dump(); // Does not help } 
+4
source share
2 answers

Where is the file located? What other file extensions are in the same folder (for example, FPT / CDX / IDX / NTX)? This should give us an idea of ​​whether it is VFP or dBase or Clipper or something else.

If this is Visual Foxpro (VFP) data, then you must install the VFPOLEDB provider from http://www.microsoft.com/en-gb/download/details.aspx?id=14839 and use one of the following connection strings from http: / /www.connectionstrings.com/visual-foxpro#vfp-ole-db-provider .

Database Container (.DBC):

 Provider=vfpoledb;Data Source=C:\MyDbFolder\MyDbContainer.dbc;Collating Sequence=machine; 

Free table directory:

 Provider=vfpoledb;Data Source=C:\MyDataDirectory\;Collating Sequence=general; 

Connect to one DBF file:

 Provider=vfpoledb;Data Source=C:\MyDataDirectory\MyTable.dbf;Collating Sequence=machine; 

Additional information on the VFPOLEDB provider at http://msdn.microsoft.com/en-us/library/aa975609%28v=vs.71%29.aspx

Of interest, as you know, is it encoded as codepage 866? Byte at offset 29 in DBF Visual Foxpro stores the code page label. See http://msdn.microsoft.com/en-us/library/aa975386%28v=vs.71%29.aspx

+3
source

I do not see evidence that you received 1252 encoded data. Your code trying to covnert from 1252 to 866 code pages failed. Thus, it is not encoded in 1252. I have currently fixed a problem in which the driver returned a string of more than one byte. Perhaps this is your problem.

Decision:

Check the key value HKLM \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Xbase \ BDE. It should be 2. If not or the key does not exist (this was my case), create a DWORD parameter and set it to 2.

More information about this key can be found here: http://support.microsoft.com/kb/307455/en-us

0
source

Source: https://habr.com/ru/post/1441490/


All Articles