We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


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

chapie asked
Medium Priority
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....
Watch Question

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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


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

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.


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."

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.


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 convert....am 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.

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.


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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.