Click here to Skip to main content
11,932,168 members (61,395 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


43 bookmarked

Paradox database native .NET reader

, 17 Mar 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Read contents of a Paradox database in pure .NET code without using BDE or other libraries; index support included.


If you are working on software which accesses a Paradox database, you are probably using BDE (Borland Database Engine). This article shows how to use Paradox database files and read some data from them directly. You can also use the primary index to find specific records you need. This could be useful if BDE doesn't cooperate with you or there is another reason why you cannot or don't want to use BDE.


Every developer sometimes has to deal with some kind of black-box - piece of technology which is not opened, and can be accessed only from some external interface, but there is a problem - the black-box is quite mysterious to us - one time it works, another time it doesn't, and whatever you do, it seems to be having its own moods. And then I always wish it would be opened so I could debug it, trace into it, and look at its teeth. Are you also a developer who has Reflector between quick links? Then you will probably understand why I started to search for some .NET native Paradox database reader. I couldn't find any, but I have found some Paradox format specifications, so I decided to write one myself and make it public for others who could use it. Many thanks to Randy Beck and Kevin Mitchell for sharing the Paradox internal structure, and because their materials are online, I will focus my efforts to describing my own code.

Paradox splits data to files using database objects - every table has its own file, and every index too. Data files and indexes have very similar structure, so we can handle them both in one class - ParadoxFile. BLOB values are also stored in their own files, but I haven't implemented the structure.

  • ParadoxFile - base class working with common structures from Paradox data files and indexes
  • ParadoxFile.DataBlock - represents one block of data
  • ParadoxFile.FieldInfo - data type of the field
  • ParadoxFile.V4Hdr - structure which is present only in certain Paradox files/versions
  • ParadoxTable - represents table data file
  • ParadoxPrimaryKey - represents table index
  • ParadoxFileType - enum with all file types
  • ParadoxFieldType - enum with all data types
  • ParadoxRecord - represents a data record
  • ParadoxDataReader - standard IDataReader implementation

The index file is, in fact, simply a table with indexes of datablocks and related indexed values. You can read it directly, but I also created a mechanism which browses through the index tree for you and picks up the desired record. You will have nothing more to do but specify a condition which you would like to apply on your data.

  • ParadoxCondition - base class for conditions which can be used for searching in index data
  • ParadoxCondition nested classes - various condition implementations
  • ParadoxCompareOperator - enum with supported compare operators (==, !=, <, <=, >, >=)

Class diagram

Using the code

One way to go is just open a table and start enumerating. This is done by the following piece of code. We will create a ParadoxTable object and use the Enumerate method to traverse through records. Data is retrieved synchronously as needed, so if we stop reading after a few records, no redundant read operations are taken.

var table = new ParadoxTable(dbPath, "zakazky");
var recIndex = 1;
foreach (var rec in table.Enumerate())
    Console.WriteLine("Record #{0}", recIndex++);
    for (int i=0; i<table.FieldCount; i++)
        Console.WriteLine("    {0} = {1}", table.FieldNames[i], rec.DataValues[i]);
    if (recIndex > 10) break;

There are, of course, scenarios where this simple method will not suffice. Sometimes we also have to read some data in the middle of a large database, so we need to use an index to minimize disk operations. In the next sample, we will use a primary key index to find records with key values in the range between 1750 and 1760. At first, the index file has to be opened, then we will create a condition composed from two compare operations. We can browse data by calling the Enumerate method on the index. In this case, we will use the ParadoxDataReader class with the the IDatareader implementation so we don't need to rewrite a lot of code if we have used BDE before.

var index = new ParadoxPrimaryKey(table, Path.Combine(dbPath, "zakazky.PX"));
var condition =
    new ParadoxCondition.LogicalAnd(
        new ParadoxCondition.Compare(
            ParadoxCompareOperator.GreaterOrEqual, 1750, 0, 0),
        new ParadoxCondition.Compare(
            ParadoxCompareOperator.LessOrEqual, 1760, 0, 0));
var qry = index.Enumerate(condition);
var rdr = new ParadoxDataReader(table, qry);
recIndex = 1;
while (rdr.Read())
    Console.WriteLine("Record #{0}", recIndex++);
    for (int i = 0; i < rdr.FieldCount; i++)
        Console.WriteLine("    {0} = {1}", rdr.GetName(i), rdr[i]);


  • read-only solution
  • not all data types are supported
  • no SQL, LINQ, or other complex queries
  • you should not work with live database during writing


  • 1.0 - Initial version
  • 1.1 - Updated Number data type support (thanks, Tonki)
  • 1.2 - Additional data type support (thanks to Mark Kuin, Christopher Erker, and Tonki again)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Petr Bříza
Software Developer (Senior) Petr Bříza
Czech Republic Czech Republic

Freelance .NET developer from Prague, Czech republic. You have a problem - I am the solution.

Visit me at

You may also be interested in...

Comments and Discussions

Generalnumeric values Pin
Tonki14-Sep-10 6:37
memberTonki14-Sep-10 6:37 
GeneralRe: numeric values Pin
Petr Bříza17-Sep-10 2:17
memberPetr Bříza17-Sep-10 2:17 
GeneralRe: numeric values Pin
Tonki18-Oct-10 3:26
memberTonki18-Oct-10 3:26 
GeneralRe: numeric values Pin
Petr Bříza16-Mar-11 22:08
memberPetr Bříza16-Mar-11 22:08 
QuestionDo you plan on implementing the BLOB structure? Pin
elemeht1-Sep-10 13:01
memberelemeht1-Sep-10 13:01 
AnswerRe: Do you plan on implementing the BLOB structure? Pin
Petr Bříza17-Sep-10 1:56
memberPetr Bříza17-Sep-10 1:56 
GeneralRe: Do you plan on implementing the BLOB structure? Pin
kaiserssosse14-Jan-11 1:03
memberkaiserssosse14-Jan-11 1:03 
GeneralRe: Do you plan on implementing the BLOB structure? Pin
Mark Kuin31-Jan-11 3:53
memberMark Kuin31-Jan-11 3:53 
I have some code which reads BLOB structures, which works in my case. I hope it helps you too. I'm not a C# developer, so it may contain some bugs...

Add this type
public delegate byte[] ReadBlobDelegate(byte[] blobInfo);

Add this field to ParadoxFile
public ReadBlobDelegate readBlob;

Add this to the DataValues property of ParadoxRecord
case ParadoxFieldTypes.BLOb:
                                    if (this.block.file.readBlob != null)                                    {
                                        byte[] blobInfo;
                                        blobInfo = new byte[dataSize];
                                        r.Read(blobInfo, 0, dataSize);
                                        val = this.block.file.readBlob(blobInfo);
                                        val = null; // not supported
                                        buff.Position += dataSize;

Add this field to the ParadoxTable class
private readonly ParadoxBlobFile BlobFile; //Added mjk

Add this code to the ParadoxTable constructor
//Added mjk
if (Path.GetFileNameWithoutExtension(file).EndsWith(".MB", StringComparison.InvariantCultureIgnoreCase) ||
    Path.GetExtension(file).Equals(".MB", StringComparison.InvariantCultureIgnoreCase))
    this.BlobFile = new ParadoxBlobFile(file);
    this.readBlob = this.BlobFile.ReadBlob;

Add this code the the ParadoxTable dispose procedure
if (this.BlobFile != null)

Add this class to the ParadoxTable class
//Added mjk
internal class ParadoxBlobFile : IDisposable
    private readonly Stream stream;
    private readonly BinaryReader reader;
    public ParadoxBlobFile(string fileName)
        : this(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
    public ParadoxBlobFile(Stream stream)
    { = stream;
        this.reader = new BinaryReader(stream);
    public virtual void Dispose()
    public byte[] ReadBlob(byte[] blobInfo)
        uint OffsetAndIndex = (uint)System.Runtime.InteropServices.Marshal.ReadInt32(blobInfo, 0);
        uint index = OffsetAndIndex & 0x000000ff;
        uint Offset = OffsetAndIndex & 0xffffff00;
        int size = System.Runtime.InteropServices.Marshal.ReadInt32(blobInfo, 4);
        int hsize = 9;
        int mod_nr = System.Runtime.InteropServices.Marshal.ReadInt16(blobInfo, 8);
        if (size > 0)
            //Console.WriteLine("Graphic index={0}; blobsize={1}; mod_nr={2}", index, blobsize, mod_nr);

   = Offset;
            byte[] head;
            head = new byte[6];
            this.reader.Read(head, 0, 3);
            //TODO check for type 2 and index=255

            this.reader.Read(head, 0, hsize - 3); //Read remaining 6 bytes of header
            int checkSize = System.Runtime.InteropServices.Marshal.ReadInt32(head, 0);
            if (checkSize == size)
                byte[] buffer;
                buffer = new byte[size];
                this.reader.Read(buffer, 0, size);
                return buffer;
        return null;

GeneralRe: Do you plan on implementing the BLOB structure? Pin
Petr Bříza16-Mar-11 22:39
memberPetr Bříza16-Mar-11 22:39 
GeneralRe: Do you plan on implementing the BLOB structure? Pin
Mark Kuin8-Nov-11 1:12
memberMark Kuin8-Nov-11 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 17 Mar 2011
Article Copyright 2010 by Petr Bříza
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid