odbc data source

Posted on 2001-09-01
Last Modified: 2013-11-20

   My question is about odbc data source

  i created a datasource called "pubs"
 now i use CDatabase to connect to this data source
 but since i am not using document-view architecture ihave to connect explicitly by aclling CDatabase::Open function, but the source whcih i am refering to has not described this function but i tried this function on my own liek this below:

 i have left all other parameters to null,
but its not working

then i used CDatabase::OpenEx() in the same manner
even that is not working properly

and after that i created an instance of CRecordset like this below:

CRecordset rec(&db); // i gave the address of CDatabase object

now had i been using doc view architecture, the framework would have called CRecordset::GetConnect to get the connect string and CRecordset::GetSqlDefault ( if i am not wrong may be its CRecordset::GetDefaultSQL) to get the sql query string, but since i am not using doc view

i called explicitly CRecordset::Open(AFX_DB_USE_DEFAULT_SETTING,"select * from employees");

the first is the default value which says that the recordset has to be a snapshot and the second is the query itself but even this is not working

and i also want to know that even if i dont use doc view architecture and say i move to the next record by calling CRecordset::MoveNext, will mfc on its own call CRecordset::DoFieldExchange() with CFieldExchange object pointer as a parameter or does it to do it only in case of doc view. If its only in case of doc view then i have to construct an object manually of Class CFieldExchange. Thi class is very important bcos it encapsulates exchange of data between CDatabase and CRecordset. So how would i create this class.

Pls i know my question is lengthy but u see ia ma so frustrated bcos i know the funda but i am not being able to put it to use practically

so pls give me the proper code pls pls pls

another point is if say i use CDatabase::Open() with username and password

how will i do it bcos my book says like this

 is admin and password here are variables, i mean how can we mention a variable name inside a string, bcos insoide string it is being considered a part of a string, not a variable name
Question by:chikersal
  • 3
  • 2

Accepted Solution

Triskelion earned 100 total points
ID: 6447968
First (in reverse order) you can build the connect string

CString strConnect;
CString strDSN="pubs";
CString strUID="admin";
CString strPassword="password";

   strDSN, strUID, strPassword);


Expert Comment

ID: 6447974
Secondly, what do you mean by "It's not working"?
Do you get a return value of true from the call to Open()?
   If so, the database is open

Does a dialog box pop up?
   If so, you're not giving it enough parameters


Author Comment

ID: 6448801
so after using this say is CDatabse::Open() works and then will i create object of CRecordset like this

CRecordset:: rec(&db) ( where db is an instance of CDatabase) and use CRecordset::Open() like this below:

CRecordset::Open(AFX_DB_USE_DEFAULT_TYPE,"select * from pubs");

is it correct and if yes then ofcourse it will generate a recordset which will be encapsulated by CDatabase. Then if i have to movethe current record from CDatabase to CRecordset i make use of CFieldExchange. My point will mfc on its own call CRecordset::DoFieldExchange() with the address of CFieldExchange object. I know in cse of doc view its this function is called by the framework. What i want to know is that if i dont use doc view, then also will it be called on its own or do i have to call CRecordset::DoFieldExchange(). bcos if i have to call this function, then how will i create the object of CFieldExchange.
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.


Expert Comment

ID: 6450642
The DoFieldExchange will be called automatically by the framework.

Did you use the ClassWizard to build the class?
If not, you should.  It handles all of the mapping and extending for you.

Expert Comment

ID: 6771976

You have a large number of questions have been open for some time, and our records show you logged in as recently as today. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.


Community Support Moderator
Experts Exchange

Expert Comment

ID: 6788704
Force/accepted by

Community Support Moderator
Experts Exchange

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Handling string inputs in C/Linux 23 168
Generic progress indicator 6 110
maxBlock challenge 30 101
Path of Workbook 3 45
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

16 Experts available now in Live!

Get 1:1 Help Now