The information in this article applies to:
SYMPTOMSThe following exception is thrown in a MFC database application: The message appears in a message box as well as in the Output window of the Visual C++ debugger. CAUSEThis exception is thrown by a record field exchange RFX function if the SQL type of the column returned in the recordset doesn't match the C type used to stored the retrieved data for that column. For example, in the MFC RFX_Text() function for Visual C++ version 1.51, you'll see the following code segment: NOTE: The RFX_Text() function supports converting SQL_LONGVARCHAR,SQL_CHAR,
SQL_VARCHAR, SQL_DECIMAL, and SQL_NUMERIC fields to a CString. If the
column that the RFX_Text() function represents has any other SQL type, you
will get the exception.There are two typical reasons why developers get the exception. First, a developer has specified a SQL statement as the second argument for the CRecordset::Open() function. In this case, the columns listed in the SQL SELECT statement must match the order by which the RFX functions are called in the CRecordset's DoFieldExchange(). The first RFX function maps to the first column returned in the recordset, the second RFX function maps to the second column, and so on. The exception is thrown when the RFX functions are out of order. Paying attention to the exception can save developers a lot of debugging time. Second, a developer intentionally changes one of the RFX functions to map the recordset column to a different C type because he or she knows the ODBC driver is capable of converting the column to any number of C types. For example, a common scenario is to have the driver return a date in a character string rather than a TIMESTAMP_STRUCT. Therefore, the developer will change the RFX_Date() function in the CRecordset's DoFieldExchange() function to a RFX_Text() function. In this scenario, the MFC RFX functions are being type strict and the exception shown above will occur. RESOLUTIONIn Visual C++ version 2.2 or greater, you will not get the exception discussed in this article. Type checking has been relaxed and now you will only see a message in the Output window: If you do not have Visual C++ 2.2 or greater and want to remove the type checking that the RFX functions provide, copy the existing RFX function into a new function and remove the the code that throws the exception. Replace the call to RFX_Text() with your new RFX_MyText() function in the DoFieldExchange() function. For example, to change the RFX_Text() function so that it doesn't do the type checking, change the code segment shown near the beginning of this article to this:
By removing the strict type checking of the RFX functions, you can use
functions like RFX_Text() to store SQL_DATE or SQL_TIMESTAMP column data in
strings rather than structures.Another alternative is to create a new RFX function that either handles the BindFieldToColumn case or calls the standard RFX function. For example, you could re-write your RFX_Text() function to be something like this:
REFERENCESFor more information about Record Field Exchange (RFX) functions, please see the following references:
Additional query words: 1.50 2.00 2.50 2.51 3.00
Keywords : kbcode kbDatabase kbMFC kbODBC kbVC |
Last Reviewed: July 30, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |