C++ Builder to read MS-Acces and/or

Posted on 1997-08-29
Last Modified: 2008-02-26
I'm new to C++ and just starting fooling around with reading the sample tables that came with the package.  Now, I have been using MS-Access on several app's and want to port them over to C++.  Also, we have started a new project at work, that involves a Btrieve database scheme.  I would like a simple explanaition for using these table formats.  This C++ newbie is way lost....
Question by:chapie
  • 4
  • 4

Accepted Solution

msmits earned 100 total points
ID: 1168416
If you have your datasources registered with ODBC, you can access them from a C++Builder program either with the ODBC API itself or you can use the data-aware control (with connection to the datasource) to access the data.
This certainly works for the MS-Access database, but I am not sure about your Btrieve database. You must have a ODBC driver for that one to have this scheme work.
Another way to access a proprietry database would be to use a library from the supplier of that database (your Btrieve stuff). MS-Access has ODBC drivers.


Author Comment

ID: 1168417
I'm aware of the documented procedure, however, everytime I attempt this I run into a brick wall about the datasource not being registered, I honestly believe if you have the experience connecting to MSaccess, then I can apply that towards Btrieve, but either 1 I attempt I get somthing like 'alias not configured properly' or something to that affect.

I decided to not reject your answer to give you the opportunity first, but I need more details on the configuration options.  If you're not certain, or unwilling, then let me know and I'll release it back into the available bank.  Thanks in advnace

Expert Comment

ID: 1168418
Here is the information that should help you underway. If you have any more questions, just say so.

To use ODBC datasource with your C++Builder program your have
to follow the following steps:

1. Register your database as a ODBC datasource.
   You do this by opening the ODBC control panel applet and
   press Add... in the 'User DSN' tab. Select the Access
   driver, type a name for your datasource and 'Select...'
   the database file you want to use.

2. Add the ODBC driver and alias for your database to the
   BDE configuration.
   You do this by opening the BDE Configuration Utility by
   selecting the 'BDE Configuration' item from the C++
   Builder submenu of the start menu.
   In the drivers tab you type a name for you driver,
   select the Access driver for the ODBC driver and select
   your previously configured ODBC data source as the
   default DSN.
   Now you define an alias for your database, supply a name
   and select the drivername as the alias type.
   Now exit the configuration utility, saving your changes.

3. Use the defined alias in your C++ Builder application.
   Start C++ Builder and put the following controls on your
   - a Data Access Table, setting the DatabaseName to the
     alias you defined, the TableName to the table you want
     to use from your database and the Active item to true
   - a Data Access DataSource, setting the DataSet to the
     table control you just added
   - Some Data Controls, like the DBText and/or DBNavigator,
     setting the DataSource to the datasource you just
     defined and the DataField to a field in your table.

Now all you have to do is run you application and see it in
action. When you just want to use the field values in your
application without the user seeing the fields on the for,
you just make them invisible and control the record of the
DBText by calling TTable member functions like First() and

You can also not use the visual aspect of C++ Builder and
just use all the described controls in your C++ code.

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.


Author Comment

ID: 1168419
Excellent detials, unfortunately, when I registered the ODBC datasource, 2 aliases were automatically setup MS Access 95 and MS Access 97, when I try to use these, I get the following msg's.  The first 1 I receive when I entere ADMIN into the log-in box that pops-up, the other I get when I don't enter anything.

"Invalid alias name MS Access 97 Database."

"General SQL error. [Microsoft][ODBC Microsoft Access 97 Driver]. General error Not enough information to connect to this DSN with SQL Connect. Use SQLDriverConnect. Alias: MS Access 97 Datase."


Expert Comment

ID: 1168420
The last error I get also when I don't select a database file when registering my ODBC via the control panel. I believe that is the only place where I need to give the path to my .mdb file.


Author Comment

ID: 1168421
Alright, I went through the control panel and added the database name that I want to use...but I have so many different MDB files that I may want to I going to have to create an ODBC source for each one, I thought that is what an alias was for, set up the source once and use the alias to define seperate databases.  With this method I am confined to 1 database per ODBC data source.

You gave me an answer so I'll give you a grade on that, but to get a better answer I'll increase the points here, as an incintive to continue, we're almost there...I just don't want to have to keep registering ODBC data sources, if all I have to do is add a new alias.

Expert Comment

ID: 1168422
Hi again.

I have a solution for changing the database of the ODBC DSN.
Use the following ODBC code:

  char *cnf_string =
    "DSN=Example Source\0DBQ=d:\\src\\DBLookup\\db2.mdb\0\0";

    "Microsoft Access Driver (*.mdb)", cnf_string);

For "Example Source" use the name you used for the datasource in the ODBC control panel and the DBQ points to the Access file.
If you want you can also give the username and password in the config string. Look is up in the ODBC reference in the Platform SDK documentation.


Author Comment

ID: 1168423
Well, not exactly the additional info I wanted, but I suppose I'll make it work, I have to move on to making the recordsources work for me now that I've managed to get them going thanks to your help.  I'll worry about finding out more details on why doing this isn't working the way I thought it would (with aliases) once I have a couple of my app's coverted from Access, then I can go back and worry about the details.  I appreciate your help, it got me connecting to both Access and Btrieve.

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question