Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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).
C++
int CDB::OpenConnection(CString strDSN, CString& strErr)
{
    CloseConnection();
      
    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);

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

    TRY
    {
         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.

Can anyone help me for finding, Where could be the problem for this exception.

Regards,

Alagar

Thanks in Advance!!
Posted
Updated 4-Jan-11 7:21am
v4
Comments
JF2015 30-Dec-10 5:49am    
Edited to fix code formatting.

Verify that the data members of your CRecordset match the Columns of the Table or Query it is attached to. I consistently encounterred this error after I added a Column to a Table and forgot to update the associated CRecordset.
 
Share this answer
 
Hi Roger,
ya both the Column name and query fields are matching
The Exception is thrown after coming out of CGlobalSet::DoFieldExchange(CFieldExchange* pFX).
But this m_pGlobalSetOpen() 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!

When I run the Debug/Release EXE,

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]

m_DataBase is an object of CDatabase class.

Where could be the problem?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900