1
votes

I'm trying to read a Paradox 5 table into a dataset or simular data structure with the view to putting it into an SQL server 2005 table. I've trawled google and SO but with not much luck. I've tried ODBC:

public void ParadoxGet()
{
    string ConnectionString = @"Driver={Microsoft Paradox Driver (*.db )};DriverID=538;Fil=Paradox 5.X;DefaultDir=C:\Data\;Dbq=C:\Data\;CollatingSequence=ASCII;";

    DataSet ds = new DataSet();
    ds = GetDataSetFromAdapter(ds, ConnectionString, "SELECT * FROM Growth");
    foreach (String s in ds.Tables[0].Rows)
    {
        Console.WriteLine(s);
    }
}
public DataSet GetDataSetFromAdapter(DataSet dataSet, string connectionString, string queryString)
{
    using (OdbcConnection connection = new OdbcConnection(connectionString))
    {
        OdbcDataAdapter adapter = new OdbcDataAdapter(queryString, connection);
        connection.Open();
        adapter.Fill(dataSet);
        connection.Close();
    }
    return dataSet;
}

This just return the error

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

I've also tired OELDB (Jet 4.0) but get the same External table is not in the expected format error.

I have the DB file and the PX (of the Growth table) in the Data folder... Any help would be much appriciated.

5

5 Answers

3
votes

I've had the same error. It appeared when I started my C# project on Win2008 64 (previos OS was Win2003 32). Also I found out that it worked fine in console apps and gave different errors in winforms. It seems that problem comes from the specifics of 32 ODBC driver working on 64-bit systems. My solution was:

// Program.cs
static void Main()
{
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        // it is important to open paradox connection before creating
        // the first form in the project
        if (!Data.OpenParadoxDatabase())
            return;
        Application.Run(new MainForm());
}

The connectionstring is common:

string connStr = @"Driver={{Microsoft Paradox Driver (*.db )}};DriverID=538;
                   Fil=Paradox 7.X;DefaultDir=C:\\DB;Dbq=C:\\DB;
                   CollatingSequence=ASCII;";

After opening connection you may close it in any place after creating first Form (if you need to keep DB closed most of time), for example:

private void MainForm_Load(object sender, EventArgs e)
{
    Data.CloseParadoxDatabase();
}

After doing that you may open and close connection every time you want during execution of your application and you willn't get any exceptions.

1
votes

Maybe this will help you out,

http://support.microsoft.com/support/kb/articles/Q237/9/94.ASP?LN=EN-US&SD=SO&FR=1 http://support.microsoft.com/support/kb/articles/Q230/1/26.ASP

It appears that the latest version of the Microsoft Jet Database Engine

(JDE) does not fully support Paradox unless the Borland Database Engine

(BDE) is also installed.

1
votes

Try to Run all The Applications with the "Run As Administrator" privileges especially run the VS.NET with "Run As Administrator "... and I am sure your problem get solved

0
votes

This isn't an answer, but more of a question: any particular reason you're trying to use C# to do the data manipulation as opposed to using SQL Server tools to load the data directly? Something like DTS or SSIS would seem like a better tool for the job.

0
votes

Thanks, I'll give that a try. I wanted to use C# so I can put it on some web pages without the extra set of putting it in SQL server.