PRB: Varchar Output Parameter Causes "Data Truncated" ErrorLast reviewed: March 12, 1998Article ID: Q182386 |
The information in this article applies to:
SYMPTOMSWhen using MFC ODBC to call a Microsoft SQL Server stored procedure that returns a CHAR or VARCHAR output parameter, the buffer intended to hold the data returned will be Null and ODBC will return the error:
Warning: ODBC Success With Info, Data truncated State:01004,Native:0,Origin:[Microsoft][ODBC SQL Server Driver] CAUSEThis problem is caused by the way that parameters are bound in the RFX_Text function. The call to SQLBindParameter appears as follows:
AFX_SQL_SYNC(::SQLBindParameter(pFX->m_hstmt, (UWORD)nField, (SWORD)pFX->m_nFieldType, SQL_C_CHAR, (SWORD)nColumnType, nMaxLength, nScale, pvParam, 0, plLength));The problem is the next to the last parameter, the cbValueMax argument, which is hard coded to 0 (zero). The cbValueMax argument specifies the length of the buffer; it applies only to character data, not to numerics. If the number of bytes available to return is greater than or equal to this number, then the driver truncates it to cbValueMax-1 and null terminates it (and throws the error above). Because the parameter is hard coded to 0, the error will always be returned.
RESOLUTIONThe resolution is to copy the RFX_Text function from Dbrfx.cpp and paste it into your project. Give it a name, such as RFX_TextOut, and then locate the SQLBindParameter call in question (right below the first UNICODE section). Change the SQLBindParameter call to the following:
AFX_SQL_SYNC(::SQLBindParameter(pFX->m_hstmt, (UWORD)nField, (SWORD)pFX->m_nFieldType, SQL_C_CHAR, (SWORD)nColumnType, nMaxLength, nScale, pvParam, nMaxLength, plLength));By using the nMaxLength input parameter, the new RFX_Text function allows the driver to set up a buffer of the correct size for the text Output parameter.
STATUSMicrosoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
Keywords : MfcDatabase Technology : odbc Version : WINNT:5.0 Platform : winnt Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |