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

Posted on 1997-08-29
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....
Question by:chapie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4

Accepted Solution

msmits earned 200 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.

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 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