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.
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 116
Separate into files by filename 12 82
lucky13 challenge 11 142
mapBully challenge 6 127
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 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