Solved

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

Posted on 1997-08-29
8
350 Views
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....
0
Comment
Question by:chapie
  • 4
  • 4
8 Comments
 
LVL 3

Accepted Solution

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

0
 
LVL 3

Author Comment

by:chapie
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
0
 
LVL 3

Expert Comment

by:msmits
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
   form:
   - 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
Next().

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

0
 
LVL 3

Author Comment

by:chapie
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."


0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:msmits
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.

0
 
LVL 3

Author Comment

by:chapie
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.
0
 
LVL 3

Expert Comment

by:msmits
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";

  SQLConfigDataSource(NULL, ODBC_CONFIG_DSN,
    "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.

0
 
LVL 3

Author Comment

by:chapie
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.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now