PRB: CLongBinary Field Truncated with SQL Server ODBC Driver

Last reviewed: July 18, 1997
Article ID: Q126264
1.50 1.51 WINDOWS kbprg kbprb

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), included with: Microsoft Visual C++ for Windows, versions 1.5 and 1.51

SYMPTOMS

When trying to update a CLongBinary field using the ODBC SQL Server driver, the data is truncated.

CAUSE

The RFX_LongBinary code tries to transfer the CLongBinary field data in 32K byte chunks, but the default maximum amount of data the SQL Server ODBC driver version can transfer at a time is 4K bytes. This only applies to driver manager (ODBC.DLL), cursor library (ODBCCURS.DLL), and SQL server driver (SQLSRVR.DLL) that came with Visual C++ version 1.50 or 1.51.

RESOLUTION

The newer ODBC SQL Server driver doesn't have a limitation on the transfer size. It is included with Visual C++ version 1.52, with the ODBC SDK version 2.1, and with the ODBC Driver pack version 2.0.

If you aren't using the newest SQL Server driver, you can work around the problem by using the ODBC API SQLSetStmtOptions() function to set the maximum amount of data that the SQL Server driver can transfer at one time. Set the value to something larger than 32K bytes.

STATUS

This behavior is by design.

MORE INFORMATION

The MFC CRecordset class has a virtual function OnSetOptions() that is a good place to make the SQLSetStmtOptions() call. In that call, specify SQL_MAX_LENGTH as the second parameter and a value of 32K bytes or greater as the third parameter. The override of the OnSetOptions() function should look something like this:

   void CMyRecordset::OnSetOptions(HSTMT hstmt)
   {
     SQLSetStmtOption(hstmt,SQL_MAX_LENGTH,(UDWORD)100000);
     CRecordset::OnSetOptions(hstmt);
   }

REFERENCES

For more information about other problems with CLongBinary fields, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q118758
   TITLE     : BUG: & FIX: Problems that Occur When Using CLongBinary Field


Additional reference words: 1.50 1.51 2.5 2.51 2.52
KBCategory: kbprg kbprb
KBSubcategory: MfcDatabase
Keywords : kb16bitonly MfcDatabase kbprb kbprg
Technology : kbMfc
Version : 1.50 1.51
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.