Recent

Author Topic: use .mdb database  (Read 13519 times)

EMN2404

  • Guest
use .mdb database
« on: April 26, 2016, 09:08:07 pm »
I converted my delphi software and got stuck with compiling. Some properties from Delphi are missing, like Connection, ComandText and Fields.

dtsConsult.Connection := MainForm.ADOConnectionExtract;
dtsConsult.CommandText := StrSQL;   
Format('%9.4f', [DBGridConsult.Fields[DataCol].AsCurrency])

What am I supposed to use instead?


wp

  • Hero Member
  • *****
  • Posts: 11857
Re: use .mdb database
« Reply #1 on: April 26, 2016, 11:48:05 pm »
"ADOConnection"? Do you use Delphi's ADO components? They are not available in Lazarus. But you can use SQLDB for get access to the mdb database:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   //connection
  4.   ODBCConnection1.Driver := 'Microsoft Access Driver (*.mdb, *.accdb)';
  5.   ODBCConnection1.Params.Add('DBQ=.\test.mdb');
  6.   ODBCConnection1.Params.Add('Locale Identifier=1031');
  7.   ODBCConnection1.Params.Add('ExtendedAnsiSQL=1');
  8.   ODBCConnection1.Params.Add('CHARSET=ansi');
  9.   ODBCConnection1.Connected := True;
  10.   ODBCConnection1.KeepConnection := True;
  11.  
  12.   //transaction
  13.   SQLTransaction1.DataBase := ODBCConnection1;
  14.   SQLTransaction1.Action := caCommit;
  15.   SQLTransaction1.Active := True;
  16.  
  17.   SQLQuery1.DataBase := ODBCConnection1;
  18.   SQLQuery1.UsePrimaryKeyAsKey := False;
  19.   SQLQuery1.SQL.Text := 'select * from Customers';
  20.   SQLQuery1.Open;
  21. end;

EMN2404

  • Guest
Re: use .mdb database
« Reply #2 on: April 27, 2016, 01:24:49 am »
Thanks, was able to compile, but when I ran the exe, it told me that it could not connect. I am attaching the captured image. What went wrong?

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: use .mdb database
« Reply #3 on: April 27, 2016, 07:00:28 am »
Is the mdb file in the same folder as the exe file?

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: use .mdb database
« Reply #4 on: April 27, 2016, 04:07:37 pm »
Hello WP.

Can you add ithis block of code in the wiki section about databases?. If it works might be useful for others.

Thanks
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: use .mdb database
« Reply #5 on: April 27, 2016, 05:29:01 pm »

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: use .mdb database
« Reply #6 on: April 27, 2016, 06:21:50 pm »
Thanks  :)
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

EMN2404

  • Guest
Re: use .mdb database
« Reply #7 on: May 06, 2016, 08:04:21 am »
Thanks for all the reply. I made a small project only to open the mdb file, but it didn't work. My mdb file contains a few dbf files, so my old Delphi program started opening the mdb file and depending what option I opened, it opened one of the dbf chosen file. Maybe a driver is missing? Checked MS website, there I found a AccessDatabaseEngine, one for 64 bits and one for 32 bits. My Windows is 64 bits, was created with Access from Office 2000 (32 bits). I installed the 32 bits of this driver, but still not able to opens mdb file.

EMN2404

  • Guest
Re: use .mdb database
« Reply #8 on: May 06, 2016, 08:05:35 am »
and yes, my mdb file is in the same folder I have my program.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: use .mdb database
« Reply #9 on: May 06, 2016, 10:38:16 am »
My mdb file contains a few dbf files
dbf inside an mdb, how can this be? Well, if you say that your old Delphi program using ADO handles this correctly, I believe you that this is possible. But with Lazarus you don't open the database with ADO, but with ODBC, and I doubt if this will work. (But this is just my gut-feeling, may be wrong...)

EMN2404

  • Guest
Re: use .mdb database
« Reply #10 on: May 07, 2016, 05:50:23 am »
Made a printscreen of the mdb file with the dbf files. Tried to upload it, but receive the message "The upload folder is full. Please try a smaller file and/or contact an administrator." - my jpg file is only 91 kb...  :o

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: use .mdb database
« Reply #11 on: May 07, 2016, 11:03:21 am »
With a few exceptions it is best to pack files into a zip for upload.

Hansvb

  • Hero Member
  • *****
  • Posts: 602
Re: use .mdb database
« Reply #12 on: May 07, 2016, 11:51:15 am »
Zeoslib has a ado connection. That works fine with Access

sfeinst

  • Full Member
  • ***
  • Posts: 230
Re: use .mdb database
« Reply #13 on: May 07, 2016, 04:43:50 pm »
There are two ways I'm aware of to have DBF files be part of Access.  One is to import - in which case then they are Access tables.  The other is to define an external link within Access.  If that is what you are doing, then the DBf files are not truly within Access, they are just links to the existing files.  How the links are defined will affect whether or not they can be found.  You need to check your links to see if they are relative or absolute file locations.  And then you need to make sure your DBF files are in that location.

I'm pretty sure that ODBC should be able to use the linked files.  You just need to make sure the files are accessible in relation to the MDB file.

EMN2404

  • Guest
Re: use .mdb database
« Reply #14 on: May 08, 2016, 04:15:36 am »
It's been too many years that I wrote this software. It was originally a Clipper program that I transformed to Delphi at a job that we worked with Delphi. I guess I imported the dbf files into Access 2000. When I open the mdb file in Access, it shows a list of the dbf files. I can double-click any of the dbf files and it opens, showing the header and the data included - does that help?  :D
Unfortunately I cannot upload the jpg file (print screen) showing the dbf files.

 

TinyPortal © 2005-2018