Problem using ADO in C++

Posted on 2005-04-21
Last Modified: 2013-11-20

I am a novice to the C++ world (just trying to write my first C++ program to access a database through ADO).

I have written a header file database.h with the following lines of code:
#import "c:\Program Files\Common Files\System\ADO\msado15.dll"
     no_namespace rename("EOF", "adoEOF")
typedef ADODB::_RecordsetPtr  RecPtr;
typedef ADODB::_ConnectionPtr CnnPtr;

I have added this header file to a Hello World Project which, I have generated through the AppWizard. The idea is to modify the same main function to use ADO and open a DB connection.

However, on compilation, I got the same error (error C2238: unexpected token(s) preceding ';). Refering to the solution suggested by Mirec in one of the questions, I added the import statement for msado20.tlb. The code now looks as below:

//Modified database.h
#undef EOF
#import "c:\Program Files\Common Files\System\ADO\msado15.dll"
     no_namespace rename("EOF", "adoEOF")
#import "c:\Program Files\Common Files\System\ADO\msado20.tlb"
     no_namespace rename("EOF", "adoEOF")
typedef ADODB::_RecordsetPtr  RecPtr;
typedef ADODB::_ConnectionPtr CnnPtr;

However, still I am getting the below error: Can you please help?

d:\c++\ado2\debug\msado15.tlh(409) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
d:\c++\ado2\database.h(3) : error C2146: syntax error : missing ';' before identifier 'rename'
d:\c++\ado2\database.h(3) : error C2501: 'no_namespace' : missing storage-class or type specifiers
d:\c++\ado2\database.h(3) : fatal error C1004: unexpected end of file found

Thanks in advance for your answer,
Question by:itsavvy_yj
    LVL 43

    Accepted Solution

    look at
    that should be off the shelf classes to wrap ADO
    LVL 6

    Assisted Solution

    //Try either:

    #pragma warning(disable : 4146)

    #import "c:\Program Files\Common Files\System\ADO\msado15.dll"  rename("EOF", "adoEOF")

    typedef ADODB::_RecordsetPtr  RecPtr;
    typedef ADODB::_ConnectionPtr CnnPtr;

    // Or try

    #pragma warning(disable : 4146)

    #import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "adoEOF")

    typedef _RecordsetPtr  RecPtr;
    typedef _ConnectionPtr CnnPtr;

    // i put #import statement on one line
    // if you specify no_namespace then you dont need ADODB:: before pointers

    Author Comment


    Thanks a lot for your valuable comments. I am now trying to connect to a Oracle Database through the ADODB. However, I am not sure what values I should passs to the Open connection call. The values of the connection string, the provider etc..

    Can you please tell me how can I open a connection?

    Thanks a ton!
    LVL 6

    Expert Comment


    I think it is the same as ole db
    LVL 2

    Assisted Solution


    CnnPtr m_spConn;
    // if using standard Oracle client (OCI):
    CString strDbName = "";
    // if using Oracle Instant Client:
    CString strDbName = "//server:port/service";
    CString strConnection = "Provider=MSDAORA;Data Source=" + strDbName;
    m_spConn->Open(strConnection, strUsername, strPassword, adConnectUnspecified);
    LVL 43

    Expert Comment

    split, all experts

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Title # Comments Views Activity
    bigDiff challenge 17 57
    Unix Command -- Challenging  question 7 65
    wordappend challenge 8 45
    Path of Workbook 3 30
    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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    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.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 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

    7 Experts available now in Live!

    Get 1:1 Help Now