Microsoft Knowledge Base Email Alertz

(271198) - The ODBC Driver Manager does not convert Unicode parameter data to ANSI during a call to the ODBC API SQLBindParameter , even when the ODBC driver involved is ANSI. If the ANSI driver saves this parameter data (that is in Unicode format) into its...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 271198 - Last Review: May 10, 2003 - Revision: 2.1

PRB: Unicode Data is not Converted to ANSI with SQLBindParameter and ANSI ODBC Driver

This article was previously published under Q271198

SYMPTOMS

The ODBC Driver Manager does not convert Unicode parameter data to ANSI during a call to the ODBC API SQLBindParameter, even when the ODBC driver involved is ANSI. If the ANSI driver saves this parameter data (that is in Unicode format) into its own internal buffer and tries to use it later, the results could be unpredictable. This problem also affects the parameter length, since Unicode strings require twice the buffer space of ANSI strings.

RESOLUTION

The ODBC driver should wait until a SQLExecute or SQLExecDirect call is made. ODBC drivers should not store parameter data or length information during the call to SQLBindParameter.

STATUS

This behavior is by design.

MORE INFORMATION

When a Unicode application calls SQLBindParameter in an ANSI driver, the ODBC Driver Manager does not immediately convert the Unicode parameter data to ANSI. The Driver Manager does an in-place conversion to ANSI only during the call to SQLExecute or SQLExecDirect, and then immediately converts the parameters back to Unicode. This is how the Driver Manager handles compatibility between Unicode applications and ANSI drivers.

It is risky if the ANSI driver saves this parameter data while it is still in Unicode format (before the SQLExecute or SQLExecDirect call) and then tries to use it later.

As per the ODBC specification, the ParameterValuePtr, which is one of the input parameters to the SQLBindParameter, is defined as follows:
The ParameterValuePtr argument points to a buffer that, when SQLExecute or SQLExecDirect is called, contains the actual data for the parameter.

REFERENCES

Microsoft ODBC 3.0 Programmer's Reference and SDK Guide, topic: "SQLBindParameter"; (Chapter 21)

APPLIES TO
  • Microsoft Data Access Components 2.0
  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
Keywords: 
kbprb KB271198
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate