Visual C++ MFC CRecordset MoveNext() error in MYSQL Database

I'm using Visual C++ ver 6.0 and have a MFC CRecordset class that connects to a readonly MYSQL database using the 3.51 MYSQL ODBC driver. The problem occurs during the MFC MoveNext() fuction when retrieiving multiple rows. The MoveNext() throws an eception with an empty error string on some records (not all) but if the error is trapped and ignored all of the records are properly retrieved. I know that VC 6.0 is dated and possibly this needs to be ported to 2005 but does anyone have an idea of what may be happening?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Deepu AbrahamR & D Engineering ManagerCommented:

Check out this link: The problem is in ODBC dBASE Driver though.

A good read on CRecordSet:

Can you post your code snippet please?

Best Regards,
>>>> The MoveNext() throws an eception
Is it really an exception? Or a debug assertion?  In the latter case you could break into the debugger and check the MFC sources around the assertion statement. There are mostly comments that tell what was wrong. In case of an exception check your output window. Most ODBC drivers are passing error messages to the debugger.

Did you check IsBOF() and IsEOF() member fucntions? Maybe the recordset already was scrolled past the end and throws an exception because of that. Then you have to call a MoveFirst before calling MoveNext.

Regards, Alex

carlmahonAuthor Commented:
Thanks, I'm checking out the the meantime here is the code snippet. I ran a debug and it apperas that this is a field truncation issue (see debug code snippet at bottom)

CTimeIPSevent tEvents(&tDatabase);
     iTime = atol((const char *) tEvents.m_timeIn);
     oTime = atol((const char *) tEvents.m_timeOut);
     CATCH(CDBException, e)
           // The error code is in e->m_nRetCode
           CString msg;
            msg.Format("Error: %s\n\n",e->m_strError);
            MessageBox(msg,"SQL Error!");

This is where the debug assertion is...*******************************************************************

void CRecordset::CheckRowsetError(RETCODE nRetCode)
      CDBException e(nRetCode);
      // Build the error string but don't send nuisance output to TRACE window
      e.BuildErrorString(m_pDatabase, m_hstmt, FALSE);
            if (e.m_strStateNativeOrigin.Find(_afxDataTruncated) >= 0)
            // Ignore data truncated warning if binding long binary columns
            // (may mask non-long binary truncation warnings or other warnings)
            if (!((m_pDatabase->m_dwUpdateOptions & AFX_SQL_SETPOSUPDATES) &&
                                                                 --->TRACE0("Error: field data truncated during data fetch.\n");
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Check your DoFieldExchange function. In case of a text field the wizard created a RFX_Text macro call which defaults to 255 char max. If you have VARCHAR2 fields greater than that they get truncated. You can expand the RFX_Text passing an additional (max) size argument (3rd argument), e. g. 1024 or more.

Regards, Alex
carlmahonAuthor Commented:
Thanks Alex - I have checked the 255 limit and there are NO VARCHAR2 fields in the DB. Just as a test there were two fields that were varchar(255) and I added the third parm to the RFX_text call but no change.

Unfornutaley I only have read acces to this database and usually (in my own DB's) I will play aroud with the fields to see what happens in the RFX. I also cannot get into the AFX field exchange call in the debugger either to see what exact column/data is causing the random issue.

Since this is a truncation error and the data fileds that I need are not affected I did an override of CRecordset::CheckRowsetError() and am now simply ignoring any errors related to a truncation.

This is working just fine but as a programmer it always nice to know what is the root of the issue since it could affect a field that someone really needs. I would like to keep this open today to see if there is any other input and a solid answer, then I will awards points accordingly.
Hmmm, truncation errors also happen if you supply a float where a double is required, or a short where you would need an int, or a byte (e. g. bool type) where you need an int as well. Also fixed char arrays could give a problem e. g. with timestamps, but DoFieldExchange uses a CString so I rather think that isn't a problem. I assume you are not using BLOBS, CLOBS, or other huge data fields. You could find out what statement is responsible by either debugging the DoFieldExchange (step over each RFX_ statement and when the exception was thrown you know where it goes wrong) or by commenting one RFX_ until the error was gone.  

If it happened somewhere in a greater result set you may spot the statement in the MFC sources where the exception was catched and put your brekpoint there. Then step up the call stack until you the RFX_ statement which cause the error. You also should see what the truncation issue is when evaluating the variables there.

Regards, Alex

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
carlmahonAuthor Commented:
Alex, thanks again - You were correct it was an RFX issue. There was a field designated simply as 'text' in the MySQL table, I was looking for varchar(??) or varchar2(??). This field in certain records was exceeding the 255 char RFX default limit. I changed the third parm to 1024 and behold no more errors. I learned a lot from this and your help was invaluable, nice job and all points to you.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.