Microsoft KB Archive/294189

= PRB: *StringLengthPtr Returns Incorrect Value When SQLGETInfo Called with Insufficient Buffer Size =

Article ID: 294189

Article Last Modified on 11/17/2003

-

APPLIES TO


 * Microsoft Data Access Components 2.1
 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.6

-



This article was previously published under Q294189



SYMPTOMS
When you call SQLGetInfo with a buffer size that is smaller than required, the string data is right-truncated as expected. According to the ODBC specification, in this situation, *StringLengthPtr should return the length of the requested information in bytes. The string passed back to the client is a regular char string (in other words, not Unicode), but when the string truncation occurs, the Driver Manager may return the length of the string in its Unicode form.

Here is an excerpt from the ODBC specification from Microsoft Developer Network (MSDN):

&quot;The buffer *InfoValuePtr was not large enough to return all of the requested information, so the information was truncated. The length of the requested information in its untruncated form is returned in *StringLengthPtr. (Function returns SQL_SUCCESS_WITH_INFO.)&quot;



CAUSE
The driver's SQLGetInfo function is always Unicode-based. The problem occurs in the Driver Manager. When the truncation occurs, the Driver Manager converts the Unicode string it receives from the driver to ANSI. However, it does not adjust the string length value accordingly, because it is allowing for a scenario where the data is entirely composed of double-byte character set (DBCS) data.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
The following steps reproduce the problem using the Microsoft ODBC Driver for Jet as an example:  Within ODBC Test, select Full Connect and connect to either a SQL Server or Microsoft Access database. On the Conn menu, click SQLGetInfo. For Info Type, enter SQL_DRIVER_NAME, and for Buffer Length, enter 12.

The driver name is returned and *StringLengthPtr shows a size of 12. Repeat step 2 but for Buffer Length, enter a buffer size of less than 12. You receive the following information:

MessageText = &quot;[Microsoft][ODBC Microsoft Access Driver]String data, right truncated &quot; *StringLengthPtr = 24



Keywords: kbprb KB294189

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.