CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Posts
    4

    Why my CRecordset::Open is throwing Exception?

    Hi,

    I'm migrating a vc6.0 code base to vs 2008. MS Access database is used. while trying to open mdb file CRecordset's Open is throwing Exception (Too few parameters. Expected 4).

    int CDB::OpenConnection(CString strDSN, CString& strErr)

    {

    CloseConnection();



    TRACE("*******DB's OpenConnection strDSN : %s strErr : %s", strDSN, strErr);



    TRY

    {
    CString str = CString("ODBC;DSN=") + strDSN;

    m_Database.Open(str);

    m_pPointSet = new CPointSet(&m_Database);
    m_pGlobalSet = new CGlobalSet(&m_Database);
    m_pFormulaSet = new CFormulaSet(&m_Database);

    if(!m_pEbExportSet->Open())

    {

    TRACE("*********DB's Connec Error Code in EbExportSet Open : %d", DB_CONNECTION_ERROR);

    return DB_CONNECTION_ERROR;

    }

    else

    {

    TRACE("**************No Exception " );

    }



    if(!m_pFormulaSet->Open())

    {

    TRACE("*********DB's Connec Error Code in FormulaSet Open : %d", DB_CONNECTION_ERROR);

    return DB_CONNECTION_ERROR;

    }

    else

    {

    TRACE("**************No Exception " );

    }

    if(!m_pGlobalSet->Open())

    {

    TRACE("*********DB's Connec Error Code in GlobalSet Open : %d", DB_CONNECTION_ERROR);

    return DB_CONNECTION_ERROR;

    }

    else

    {

    TRACE("**************No Exception " );

    }



    }

    CATCH_ALL( e )

    {

    LPTSTR lpErr = strErr.GetBuffer(255);

    e->GetErrorMessage(lpErr, 255);

    strErr.ReleaseBuffer();



    TRACE("Error String : %s ", strErr);



    LogException(strErr, "OpenConnection");

    TRACE("................logged.............\n");

    return DB_EXCEPTION;

    }

    END_CATCH_ALL



    return SUCCESS;

    }

    m_pEbExportSet, m_pFormulaSet, m_pGlobalSet are objects of class derived from CRecordset. Only m-pGlobalset->Open() is throwing exception, remaining is working fine.

    The Exception is thrown after coming out of CGlobalSet:oFieldExchange(CFieldExchange* pFX).
    But this Open() is working fine in VS2008 environment (ie when I execute using Ctrl+F5 or F5), but after building when I run exe its not working!

    In Debug mode,

    m_DataBase.Open() produces following Messages,

    [3772] Warning: ODBC Success With Info,
    [3772] Driver's SQLSetConnectAttr failed
    [3772] State:IM006,Native:0,Origin:[Microsoft][ODBC Driver Manager]

    [3772] DBMS: ACCESS
    [3772] Version: 04.00.0000
    [3772] ODBC Driver Manager Version: 03.52.0000


    and m_pGlobalSet->Open() produces following Messages,

    [3772] Too few parameters. Expected 4.
    [3772] State:07001,Native:-3010,Origin:[Microsoft][ODBC Microsoft Access Driver]


    Sorry for such a long question. To avoid misinterpretation only I lengthened my question!


    Regards,

    Alagar


    Thanks in Advance!!

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Why my CRecordset::Open is throwing Exception?

    First, please use code tags when posting code. The code is unreadable and unformatted, which is probably the reason why no one has responed to you.

    Secondly, you have all of these classes derived from CRecordSet, but we have no idea if you did anything in these classes to cause the issue. You should post your code for these classes.

    Third, you can just debug a release build by changing compiler options to include debugging info. Since the problem appears in the release version, then that is what you should try to do.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jan 2011
    Posts
    4

    Re: Why my CRecordset::Open is throwing Exception?

    Hi Paul,
    Thanks for your advise. This is my first post and dont know to attach code snippets. So kindly adjust for this post.


    //In GlobalSet.h


    class CGlobalSet : public CRecordset
    {
    public:
    CGlobalSet(CDatabase* pDatabase = NULL);
    DECLARE_DYNAMIC(CGlobalSet)

    CString m_strDSN;

    int GetRecCount();
    int RequeryFail();

    //some data members

    public:
    virtual CString GetDefaultConnect(); // Default connection string
    virtual CString GetDefaultSQL(); // Default SQL for Recordset
    virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support

    }



    //In GlobalSet.cpp


    CString CGlobalSet::GetDefaultConnect()
    {
    return m_strDSN;
    }

    CString CGlobalSet::GetDefaultSQL()
    {
    return _T("[GLOBALS]");
    }

    #ifdef _DEBUG
    void CGlobalSet::AssertValid() const
    {
    CRecordset::AssertValid();
    }

    void CGlobalSet:ump(CDumpContext& dc) const
    {
    CRecordset:ump(dc);
    }
    #endif //_DEBUG


    int CGlobalSet::GetRecCount()
    {
    int nCount = 0;

    MoveFirst();
    while (!IsEOF())
    {
    nCount ++;
    MoveNext();
    }

    MoveFirst();
    return nCount;
    }

    // please open the recordset again, it is closed if fails to requery
    int CGlobalSet::RequeryFail()
    {
    if (!IsOpen())
    {
    m_strFilter.Empty(); // clear the filter, then open
    if (!Open())
    {
    TRACE("**********************DB Connection Error -99******************");
    return DB_CONNECTION_ERROR;
    }
    }
    TRACE("**********************DB Query Error -97******************");
    return DB_QUERY_ERROR;
    }

    void CGlobalSet:oFieldExchange(CFieldExchange* pFX)
    {
    TRACE("************************CGlobalSet's DoFieldExchange.*****************");
    //{{AFX_FIELD_MAP(CGlobalSet)
    pFX->SetFieldType(CFieldExchange:utputColumn);
    RFX_Bool(pFX, _T("[OnlineUpdate]"), m_bOnlineUpdate);
    RFX_Bool(pFX, _T("[WriteToHexLog]"), m_bWriteToHexLog);
    RFX_Bool(pFX, _T("[WriteToSOE]"), m_bWriteToSOE);
    RFX_Text(pFX, _T("[SOE_DSN]"), m_strSOE_DSN);
    RFX_Text(pFX, _T("[User]"), m_strUser);
    RFX_Text(pFX, _T("[Password]"), m_strPassword);

    //// some more exchanges

    //}}AFX_FIELD_MAP
    TRACE("************************CGlobalSet's DoFieldExchange ENDS.*****************");
    }

    Regards,
    Alagar

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured