• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

Connecting two database


  I know that we can connect two database in an aplication.  I'm using Access Database and ODBC MFC Database classes/CRecordset to access the database.  In my aplication, I want to retrieve data from two different database in a single document or dialog box, is that possible?

  I don't know where I should create the multiple CDatabase.

  I need a step by step instructions how to make the program work.

  Thank you.
  • 2
1 Solution
Since you are using Access database, I would first suggest that you use DAO classes. MS recommends that you use this.
But if your requirement is that you have to use ODBC, it is no problem.

What you want *can* be done. If you give some more info about your app, it would be more useful for giving better suggestions.

Anyway, what you should to do is:
1. Derive 2 classes from CRecordset for the two databases.
2. Construct 2 CDatabase objects.
3. Open the databases.
4. Construct the objects for the recordset and open them.

You are ready now. For example:

Suppose you have derived CSet1 and CSet2 from CRecordset.

CDatabase* db1, db2;

CSet1 rsSet1(db1);
CSet2 rsSet2(db2);


/* Read the records*/

/* Read the records*/


hamidahAuthor Commented:
 Hi, thank you for your answer.  Let me tell you a little more about the application.  I have a dialog box.  In the dialog box there are four edit box, two box will retrieve from one database and two others will retrieve data from another database.  I use MFC AppWizard(exe) to start my project and then add two new class derived from recordset for the two databases.  What happened now is, when i run the application there is a "debug assertion failed' error.  Or if I use a single document with database view, only two edit box will display data from one database.

  What is wrong?  Will you help me?

  Thank you.
Debug to find out what is causing the assertion failure. Only then you can find out the reason for it.

If you are displaying the records in the dialog box, then you declare the database and recordset as member of your dialog class. You should open the database, read records and set the edit box text in OnInitDialog().

Or you can use CRecordView. I have never used it, so I cannot be of much help to you.

All the best.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now