[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

odbc data source

Posted on 2001-09-01
6
Medium Priority
?
374 Views
Last Modified: 2013-11-20
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
Comment
Question by:chikersal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
Triskelion earned 400 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";


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

CDatabase::Open(strConnect);
0
 
LVL 6

Expert Comment

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


0
 

Author Comment

by:chikersal
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.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 6

Expert Comment

by:Triskelion
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.
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6771976
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
 
LVL 5

Expert Comment

by:Netminder
ID: 6788704
Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

649 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