Old Trick: Retrieving MDB MS Access 97 Files from Borland Delphi
Somehow, I’ve been involved with a project contains dated database file from Ms Access (MDB) and Dbase IV type (DBF). The goal is to converting database and it’s value from MDB into DBF. For this purpose, still I develop the application using Borland Delphi 6.
On this experience, I prepare the form with 3 database component; TADOConnection, TADOQuery (for MDB) and TTable (for DBF)
For first initialization MDB files using a connection string, here below my example how to get it done:
While Edit1.Text contains drive name & full path where the MDB file exist on local storage. TADOQuery used to retrieve record using SQL query as usual used on TQuery. But note that the SQL syntax between MDB and others database is not exactly the same. You need to carefully type the correct query or you can test it first from MS Access query window.
After it succeeded, retrieve MDB records using TADOQuery, now turn to DBF migration operation. Sometimes, original DBF record using MDX index file. If there’s no MDX files found, it needs to be force so that the application still can read the DBF files & doing operation within. Here below I create a procedure in order to force to by-passing the need of MDX files:
The above procedure will execute twice from the TButton action trigger & forcing nonexistence of MDX file. It’s mean that, after TButton pressed, an error window will show up & try except lines will be executed. Next, DBF reading process will be executed again automatically (PostMessage(btnProses.Handle, cn_Command, bn_Clicked, 0)). Have a great experiment on this!
On this experience, I prepare the form with 3 database component; TADOConnection, TADOQuery (for MDB) and TTable (for DBF)
For first initialization MDB files using a connection string, here below my example how to get it done:
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'+'User ID=Admin;Data Source='+Edit1.Text+';Mode=Share Deny None;'+'Persist Security Info=False;';
While Edit1.Text contains drive name & full path where the MDB file exist on local storage. TADOQuery used to retrieve record using SQL query as usual used on TQuery. But note that the SQL syntax between MDB and others database is not exactly the same. You need to carefully type the correct query or you can test it first from MS Access query window.
After it succeeded, retrieve MDB records using TADOQuery, now turn to DBF migration operation. Sometimes, original DBF record using MDX index file. If there’s no MDX files found, it needs to be force so that the application still can read the DBF files & doing operation within. Here below I create a procedure in order to force to by-passing the need of MDX files:
try
Table1.Close;
Table1.DatabaseName:=extractfilepath(extractfilepath(application.ExeName)+filename+'.DBF');
Table1.TableName:=filename+'.DBF';
Table1.Active:=false;
Table1.EmptyTable;
Table1.Open;
except
on E: EDBEngineError do
if Pos('Index does not exist', E.Message) > 0 then
begin
MessageDlg('MDX file not found.Attempting to Open without Index.', mtWarning, [mbOK], 0);
RemoveMDXByte(extractfilepath(application.ExeName)+filename+'.DBF');
PostMessage(btnProses.Handle, cn_Command, bn_Clicked, 0);
end;
end;
The above procedure will execute twice from the TButton action trigger & forcing nonexistence of MDX file. It’s mean that, after TButton pressed, an error window will show up & try except lines will be executed. Next, DBF reading process will be executed again automatically (PostMessage(btnProses.Handle, cn_Command, bn_Clicked, 0)). Have a great experiment on this!
Labels: Delphi, Programming
PS: If you've benefit from this blog, you can support it by making a small contribution. |
Alex said,
Monday, April 19, 2010 2:57:00 AM
I know a lot of other types of files. But one of them,such as access files I din't know what to do next. Yesterday something happened with its. And I used the next software - Recovery Access. The utiltiy solved my issue for seconds and for free as far as I remembered.
Eko Wahyudiharto said,
Monday, April 19, 2010 7:54:00 AM
As it's name, the Recovery Toolbox purposed to repair a damaged access file. Another tool you may try is Access PassView v.1.12