Search code examples
c#.netdatabaseparadox

How to read and write to a Paradox 7.x database from .NET app?


I develop .NET application (C#) and I need to read and update some data in a Paradox 7.x database.

According to Microsoft article for Paradox 7-8 no support is provided for OLEDB.

According to another SO question reading is possible, but not writing.

So is there any approach (maybe some third-party library or some BDE wrapper) how can I read and write to Paradox 7.x database?

UPDATE I've tried OleDB approach:

var builder = new OleDbConnectionStringBuilder();
builder.DataSource = "D:\\MyBase\\";
builder.Provider = "Microsoft.Jet.OLEDB.4.0";
var connection = new OleDbConnection(builder.ToString() + ";Extended Properties=Paradox 5.x");
var command = new OleDbCommand("SELECT * FROM Planes", connection);

connection.Open();
using (var reader = command.ExecuteReader())
     if (reader.HasRows)
         while (reader.Read())
               listBox1.Items.Add(reader.GetString(2));

This one fails with OleDbException (expectable because my database has Paradox 7.x format):

External table is not in the expected format

If I change connecton string to Extended Properties=Paradox 7.x - that one fails with enother OleDbException (expectable because Paradox 7 is not supported by OLEDB according to Microsoft article))

Invalid operation

I've tried ODBC approach:

var connectionString = "Driver={Microsoft Paradox Driver (*.db )};" 
                + "DriverID=538;Fil=Paradox 7.X;"
                + "DefaultDir=D:\\MyBase\\;"
                + "Dbq=D:\\MyBase\\;"
                + "CollatingSequence=ASCII;";

var connection = new OdbcConnection(connectionString);
var command = new OdbcCommand("SELECT * FROM Planes", connection);

connection.Open();
using (var reader = command.ExecuteReader())
      if (reader.HasRows)
            while (reader.Read())
                  listBox1.Items.Add(reader.GetString(2));

That one also fails with OdbcException

ERROR [HY000] [Microsoft] [Paradox ODBC driver] External table is not in the expected format

So nothing work nor now..


Solution

  • So finally I managed read and even write Paradox 7.x database via Microsoft.Jet.OLEDB.4.0 (decpite of Microsoft tells us that Paradox 7-8 is not supported):

    1. Install AccessDatabaseEngine for Office 2007 (32bit)
    2. Install AccessDatabaseEngine for Office 2010 (32bit) (choose AccessDatabaseEngine.exe)
    3. Install BDE 5.1.1.1 (It's better to install somewhere like D:\BDE)
    4. Via BDE Administrator change NET DIR from C:\ to any folder, where you have write privileges (I've changed to D:\BDE)

    After following code works like a charm

    var builder = new OleDbConnectionStringBuilder();
    builder.Add("Provider", "Microsoft.Jet.OLEDB.4.0");
    builder.Add("Data Source", @"D:\MyBase\");
    builder.Add("Persist Security Info", "False");
    builder.Add("Extended properties", "Paradox 7.x; HDR=YES");
    var connection = new OleDbConnection(builder.Tostring()); 
    var command = new OleDbCommand("SELECT * FROM Planes", connection);
    //reading
    connection.Open();
    using (var reader = command.ExecuteReader())
         if (reader.HasRows)
             while (reader.Read())
                   listBox1.Items.Add(reader.GetString(2));
    //writing
    command = new OleDbCommand("DELETE * FROM Planes", connection);
    command.ExecuteNonQuery();
    connection.Close();
    

    Hope this information will help somebody like me.