Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: MBCS Encoded Strings Are Truncated in ADO 2.1


View products that this article applies to.

This article was previously published under Q293859

↑ Back to the top


Symptoms

When you pass multi-byte character set (MBCS) encoded strings to a database, the string may be truncated, and no error is returned.

↑ Back to the top


Cause

Microsoft ActiveX Data Objects (ADO) versions 2.1 Service Pack 2 (SP2) and earlier correctly determine the number of characters but do not correctly convert this to the bytes that are needed to store the string. Some languages use multiple bytes to store one character. The string is truncated because of this byte miscalculation.

↑ Back to the top


Resolution

To resolve this problem, Microsoft strongly recommends that you upgrade to ADO version 2.5, which is part of Microsoft Data Access Components (MDAC) version 2.5.

This problem does not affect Microsoft Windows 2000 users because MDAC 2.5 is already included with the Windows 2000 installation.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Data Access Components version 2.5.
You can download the latest version of MDAC from the following Microsoft Web site:

↑ Back to the top


More information

Steps to Reproduce Behavior

NOTE: This sample only fails on a computer that is running a double-byte character set (DBCS) version of Windows (for example, Japanese or Chinese) and MDAC 2.1 or earlier.
  1. Create a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. From the Project menu, click References, and then select the Microsoft ActiveX Data Objects 2.1 check box.
  3. Add a CommandButton control to Form1.
  4. Add the following code to the Command1_Click event:
    Private Sub Command1_Click()
        Dim cnn1 As New ADODB.Connection
        Dim Cmd As New ADODB.Command
        Dim str As String
        Dim rows As Variant
        
        On Error GoTo AdoError
        
        str = "[MULTIBYTE CHARACTER STRING]"
        strCnn = "Driver={SQL Server};server=find;uid=sa;password=;database=pubs"
        
        cnn1.Open strCnn
        
        Cmd.ActiveConnection = cnn1
        Cmd.CommandText = "UPDATE jobs SET job_desc=? WHERE job_id=1"
        Cmd.CommandType = adCmdText
             
        Cmd.Execute rows, str, -1
        cnn1.Close
        
        MsgBox "Works"
        Exit Sub
        
    AdoError:
        Dim errLoop As Error
        Dim strError As String
    
        ' Enumerate Errors collection and display properties of
        ' each Error object.
        Set Errs1 = cnn1.Errors
        For Each errLoop In Errs1
              str = errLoop.Description
              str = str + "SQL state:"
              str = str + errLoop.SQLState
              str = str + " Native error:"
              str = str + errLoop.Description
              
              MsgBox str
        Next
    End Sub
    					
  5. Replace [MULTIBYTE CHARACTER STRING] with a valid multi-byte character string. Change the SQL Server ConnectionString to point to a valid server.

    NOTE: Depending on which version of MDAC and Microsoft SQL Server is installed, you may or may not receive an error message. To verify the data, use SQL Server tools or the Data View window to locate the record in the table. Most likely, the data is only viewable on multi-byte versions of Windows.

↑ Back to the top


Keywords: KB293859, kbfix, kbdatabase, kbbug

↑ Back to the top

Article Info
Article ID : 293859
Revision : 6
Created on : 5/17/2007
Published on : 5/17/2007
Exists online : False
Views : 416