Board index » delphi » MS Access 2.0 .mdb files via ODBC in Delphi

MS Access 2.0 .mdb files via ODBC in Delphi

For all of you trying to get access to MS Access 2.0 .mdb
database files via ODBC drivers in Delphi.  Here's how:

[Before I continue, however, I must warn you that accessing
 databases via the ODBC drivers is much slower than accessing
 Paradox or dBase databases directly.  Also, this procedure appears
 to work for both 16-bit and 32-bit versions of Delphi and ODBC.  
 Anyhow, on with the show...]

1. First, you must get the latest ODBC drivers for your operating
   system.  Go to URL...

      http://www.webbase.com/odbcC.htm  

   and get them.  Install these first!

2. Next, we'll create an ODBC connection to the database:
   a) Open Control Panel.
   b) Start the ODBC service.
   c) When the Data Sources dialog appears, press "Add...".
   d) If the ODBC drivers have been installed correctly, select
      "Microsoft Access Driver (*.mdb)" from the list of
      Installed ODBC Drivers.  Once selected, press "OK".  NOTE:
      If listed, do not select either the "Access Data (*.mdb)"
      or "Access Files (*.mdb)" from the list.
   e) Next, you'll be presented with the ODBC Microsoft Access ver
      Setup dialog.  Type-in a unique, one word name for the Data
      Source Name -- preferably, with 8 characters or less (like a
      DOS filename).  Type-in a full description.  Then, press
      "Select..." to select the database file.  Upon completion,
      press "OK".
   f) If your new Data Source is listed, press "Close" to close the
      Data Sources dialog, then exit Control Panel.

3. After making the proper ODBC database connections, we must inform
   Delphi about your new ODBC database:
   a) Open the BDE Configuration Utility.  This program should be
      located in your \delphi\bde directory.
   b) Press the "New ODBC Driver" button.
   c) Give your "SQL Link Driver" a name.  Preferably for SQL, 12
      upper case characters or less, with a possible underscore.
   d) From the "Default ODBC Driver" drop-down listbox, select
      "Microsoft Access Driver (*.mdb)" item.
   e) If your new data source does not show in the "Default Data
      Source Name" drop-down listbox, then select it.  It should be
   f) the same name you typed-in for step 2.5, above.
   g) If everything is setup properly, press "OK" to go back to the
      BDE Configuration Utility.  Your ODBC driver name should appear
      in the "Driver Name" listbox.  If so, continue...
   h) Next, press the "Aliases" tab, then press the "New Alias"
      button.
   i) In the Add New Alias dialog, enter a "New alias name".  You can
      use the same name you typed-in for step 2.5, above.
   j) For the "Alias type" drop-down listbox, select your SQL Link
      name (it begins with "ODBC_").
   k) If everything is setup properly, press "OK" to go back to the
      BDE Configuration Utility.  Your new alias name should appear
      in the "Alias Names" listbox.  If so, continue...
   l) Finally, pull down the "File" menu and select "Save".  Then
      exit the BDE Configuration Utility.

4. These final steps are optional, since they involve getting into
   Delphi and viewing your ODBC database:
   a) Start Delphi.
   b) Create a new project, application, or form.
   c) In the new form, add a TTable component, TDataSource component,
      and a TDBGrid component.
   d) For the TDBGrid component, set these properties:
      i. DataSource := DataSource1
   e) For the TDataSource component, set these properties:
      i.   DataSet := Table1
      ii.  For the TTable component, set these properties:
      iii. DatabaseName := name of your ODBC database.
      iv.  SessionName := Default.
      v.   TableName := select a table from the database.
      vi.  TableType := ttDefault
   f) Next, double-click on the TTable component residing on your
      form -- this invokes the Field editor.  Right-click in the
      listbox to invoke the pop-up menu.  Select the "Add fields..."
      menu item.  In the Add Fields dialog, ensure that all available
      fields are selected, then press "OK".  Once all the fields are
      listed in the listbox, close the Field editor.
   g) Finally, set the "Active" property of the TTable component to
      "True" and watch the TDBGrid fill-in with data!

Hope this cures your ODBC blues with Delphi...

Enjoy,
-Jim Rofkar.

 

Re:MS Access 2.0 .mdb files via ODBC in Delphi


James D. Rofkar <jim_rofkar%lotusnot...@instinet.com> wrote in article
<324A7CA7....@instinet.com>...

Quote
> For all of you trying to get access to MS Access 2.0 .mdb
> database files via ODBC drivers in Delphi.  Here's how:

[Instructions cut; see message above]

Alternatively, use ODBCExpress, and avoid the BDE completely.
This will give much faster ODBC access (albeit still not quite native
speed), and the interface to Delphi is a lot simpler too. You still
need the ODBC drivers though...

TTFN
        Ade.

Re:MS Access 2.0 .mdb files via ODBC in Delphi


James D. Rofkar <jim_rofkar%lotusnot...@instinet.com> wrote in article
<324A7CA7....@instinet.com>...

Quote
> For all of you trying to get access to MS Access 2.0 .mdb
> database files via ODBC drivers in Delphi.  Here's how:
> Before I continue, however, I must warn you that accessing
> databases via the ODBC drivers is much slower than accessing
> Paradox or dBase databases directly.  Also, this procedure appears
> to work for both 16-bit and 32-bit versions of Delphi and ODBC.  
> 1. First, you must get the latest ODBC drivers for your operating
>    system.  Go to URL...

>       http://www.webbase.com/odbcC.htm  
> 2. Next, we'll create an ODBC datasourse  to the database:
> 3. After making the proper ODBC database datasource, we must inform
>    the Delphi BDE about your new ODBC database
> 4. These final steps are optional, since they involve getting into
>    Delphi and viewing your ODBC database:
> Hope this cures your ODBC blues with Delphi...

Accessing databases via ODBC is only slow because of the BDE layer in
Delphi.  The BDE needs to be configured for every database you need to
access by setting up SQL Links and aliases.  

It is much faster to bypass the BDE and access the ODBC driver directly
using ODBC Express for Delphi.  No configuration necessary, no extra deploy
files.

ODBC Express is also much easier to use than the BDE.

Check out the home page at http://www.adam.co.za

Happy ODBC programming!

Roger Weiss.

Re:MS Access 2.0 .mdb files via ODBC in Delphi


Another option is Opus Direct Access. It works very well.

http://www.opus.ch/

nb.

Quote
James D. Rofkar wrote:

> For all of you trying to get access to MS Access 2.0 .mdb
> database files via ODBC drivers in Delphi.  Here's how:

.....

nb.

Other Threads