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

odbc data source

Sir,

   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:

  CDatabase::Open("ODBC;DSN=pubs");
 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

CDatabase::Open("ODBC;DSN=pubs;UID=admin;PWD=password");
 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
0
chikersal
Asked:
chikersal
  • 3
  • 2
1 Solution
 
TriskelionCommented:
First (in reverse order) you can build the connect string

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


strConnect.Format("ODBC;DSN=%s;UID=%s;PWD=%s",
   strDSN, strUID, strPassword);

CDatabase::Open(strConnect);
0
 
TriskelionCommented:
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


0
 
chikersalAuthor Commented:
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.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
TriskelionCommented:
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.
0
 
NetminderCommented:
chikersal,

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.

http://www.experts-exchange.com/jsp/qShow.jsp?qid=11443178
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11964778
http://www.experts-exchange.com/jsp/qShow.jsp?qid=12043279
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11564958
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20104338
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20104344
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20105195
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20107021
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20117736
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20123376
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20128779
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11146525
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11559878
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11540439
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20158555
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20174325
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20176309
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20177269
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20183746
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20184309
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20188568
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20260766
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20260773
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20262003

Thanks,

Netminder
Community Support Moderator
Experts Exchange
0
 
NetminderCommented:
Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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