Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

ADO OLE MFC

I have been using MFC CRecordset CDatabase for some time. With VB I use ADO.
Well, I am starting a small new project and want to use different database access methods under VC++, such as ADO. But after looking through this site, does not look like many people use this.

?If I want to enhance my skill set, should I look into ADO or OLE under VC++ 6.0.
?If so, which one, and links to some tutorials.
?What about OLE DB consumer templates, what the hell is this?
?Are there wizards in VC++ 6.0 that help with integerating ADO such as with CRecordset class or is it all straight coding.

Back-end db is SQL server 7.0




0
Paullkha
Asked:
Paullkha
  • 3
  • 2
1 Solution
 
DanRollinsCommented:
>>?If I want to enhance my skill set, should I look into ADO or OLE under VC++ 6.0.
Probably OLEDB since it is the coming wave.  But you will find more examples in MDSN and elsewhere for ADO.  Both are infinitely harder to use than CRecordset objects.

>>?Are there wizards in VC++ 6.0 that help with
>> integerating ADO such as with CRecordset class or is it
>> all straight coding.
All straight coding, and not much of it is easy.  If you use CRecordset, the tne ClassWizard makes named variables for each field of each table.  Change the table and the ClassWizard can update your object with a few clicks.

If you use ADO or OLEDB, you will be digging around all through your code to locate the changed spelling of the table/field name.  And the error won't occur unti runtime (then the data provider says "I've never heard of that field" and rejects the whole query.)

-- Dan
0
 
DanRollinsCommented:
Incidently, here is the best code sample for ADO access that I've ever seen.  It is PERFECT because it does the bare minimum:

#include <stdio.h>
#include <afxdisp.h>
#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace

#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \
                                  if (FAILED(_hr)) _com_issue_error(_hr); }

#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value
#define UC (char *)
struct InitOle {
    InitOle()  { ::CoInitialize(NULL); }
    ~InitOle() { ::CoUninitialize();   }
} _init_InitOle_;       // Global Instance to force load/unload of OLE

void main(){
    _RecordsetPtr   spRS;
    _ConnectionPtr  spCON;
    try{
        CREATEiNSTANCE(spCON,Connection);
        spCON->ConnectionString = L"driver={sql server};SERVER=(local);Database=pubs;UID=sa; PWD=;";
        // spCON->ConnectionString =L"DRIVER={Microsoft Access Driver (*.mdb)};DBQ=authors.MDB;DefaultDir=C:\\test;";
             
        spCON->Open( "", "", "", -1 );
        CREATEiNSTANCE(spRS,Recordset)
        spRS->PutRefActiveConnection( spCON );
        spRS->Open("select au_lname, au_fname from authors",
               vtMissing, adOpenKeyset,
            adLockBatchOptimistic, -1
          );
        while(spRS->adoEOF == false){
            printf("au_lname = %s  au_fname = %s \n",
                    UC _bstr_t(RsITEM(spRS,0L)),
                    UC _bstr_t(RsITEM(spRS,"au_fname"))
               );
            spRS->MoveNext();
        }
        spRS->Close();
        spCON->Close();
    }
    catch( _com_error &e){
        _bstr_t bstrSource(e.Source());
        _bstr_t bs =  _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ")
            + _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ")
            + _bstr_t(e.Description());
       
        MessageBox(0,bs,bstrSource, MB_OK);
    }          
}

-- Dan
0
 
PaullkhaAuthor Commented:

Looks like no-one else disagrees.

When should one use ADO over the CRecordset object, since my reservations about ADO seem validated? I have seen it used in some examples on the web, but are there any compelling reasons to use it?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
DanRollinsCommented:
ADO vs CRecordset:

With ADO and OLEDB, you use table/field names directly --  so your code looks about the same whether you are programming in VB, JavaScript, or C++ (of course C++ has all of that ugly COM overhead, as I've said).  And you can write very flexible SQL commands.  The data comes and goes as VARIENT data type which is very convenient for VB and JS, but awkward in C++.

With CRecordset, you let the framework transfer data between member variables and the database.  A VARCHAR data type comes in as an easy-to-use CString, etc.  The drawback is that there is a lot of 'inflexible' binding going on.  For instance, even if all you need is three columns, you will probably use a CRecordset that populates all member fields.  That means that there is a lot of data transfer going on that you don't need.

-- Dan
0
 
MoondancerCommented:
This question is current, others are not and need your attention.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still inactive in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20292692.html
http://www.experts-exchange.com/questions/Q.20255048.html
http://www.experts-exchange.com/questions/Q.20284498.html
http://www.experts-exchange.com/questions/Q.20284957.html
http://www.experts-exchange.com/questions/Q.20293564.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20089266.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
MoondancerCommented:
Thank you for returning and finalizing this.
Moondancer - EE Moderator
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

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