Microsoft KB Archive/216443

= FIX: CString::Format Involving Floats Reallocates the Default Bound ODBC Text Buffer =

Article ID: 216443

Article Last Modified on 11/17/2003

-

APPLIES TO


 * Microsoft Open Database Connectivity 3.51
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q216443



SYMPTOMS
" "While performing the CRecordset::Update function using dynaset cursors on a table containing a numeric or decimal field(s) the following error message appears:

Debug Assertion Failed!

Program: Name of the Program

File: dbrfx.cpp

Line: 287

This happens when the CString::Formatoperation involving floating point numbers is performed on a CString member variable bound to the decimal or numeric field(s) in the table prior to the update.



CAUSE
In Visual C++ version 6.0, the minimum number of characters to represent a float in a CString has been increased from 128 to 312. By default, RFX_Text binds a 256 byte buffer to a text column if a CString::Format is performed on a CRecordset bound member variable as in the following example: CString m_MemberVariable; m_MemberVariable.Format("%7.2f ",111.11); Consequently, the buffer is reallocated. In MFC ODBC, a variable is bound to a field in the table only during CRecordset::Open. Once bound, its binding address must remain valid as long as the ODBC binding remains in effect. The reallocation causes this binding address to change and results in the debug assertion.



RESOLUTION
Set the fourth parameter of RFX_Text (nMaxLength) to be greater than or equal to 312. This ensures that the CString buffer allocated for the variable bound to the numeric or decimal field is at least 312 bytes, thereby avoiding the reallocation on a CString::Format.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3.

For more information about Visual Studio 6.0 Service Packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed

