Microsoft KB Archive/321909

= BUG: ATL OLE DB provider returns incorrect length for variable-length string field =

Article ID: 321909

Article Last Modified on 9/13/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-



This article was previously published under Q321909



SYMPTOMS
When you use an Active Template Library (ATL) provider template to create an OLE DB provider that is linked to a server that is running Microsoft SQL Server, the linked server returns garbage characters for the variable-length field.



CAUSE
This problem occurs because of a bug in the TransferData method call code of the ATL OLE DB provider template.



RESOLUTION
To work around this problem, change the following items in the Atldb.h file:   In TransferData method call, locate line 7329, which appears as follows: if(pBindCur->dwPart & DBPART_LENGTH )   Comment out the following two lines, which appear inside this if condition: if (!(pBindCur->dwPart & DBPART_VALUE)) cbDst = cbCol; // You do not have the data convert to correct this.   Add the following code to line 7310: cbDst=cbCol; NOTE: Line 7310 appears after the end of the switch block and before the following code: // Handle cases in which you have provider-owned memory. NOTE: These should be       // with DBTYPE_BYREF (otherwise, this does not make sense). if (pBindCur->dwPart & DBPART_VALUE) {           if (pBindCur->dwMemOwner == DBMEMOWNER_PROVIDEROWNED && pBindCur->wType & DBTYPE_BYREF) ......  Save your changes as a new file that is named Atldbnew.h, and then use the Atldbnew.h file in your provider code.

This code change assigns the real string length to the obLength property of the binding structure for the provider-owned memory scenario.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Use the ATL OLE DB Provider Wizard to create a provider, and then accept all of the default options.</li> Use this provider to create a SQL Server linked server, and then click Run In-Proc for the provider option.</li>  Run the following query:

<pre class="fixed_text">select * from OPENQUERY(P2,'c:\*.*')

Notice that you receive the following result (or a similar one), which contains garbage characters for the variable-length field: FileAttributes FileSizeHigh FileSizeLow FileName                                                                                                                                                                                                                                                         AltFileName --   -- 8224           0            4346         2000_10_18_WaterlooMaple.rtf ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 2000_1~1.RTF 8208          0            0            Alert 0_18_WaterlooMaple.rtf ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 34            0            0            AUTOEXEC.BAT terlooMaple.rtf ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 8208          0            0            BACKUP C.BAT terlooMaple.rtf ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 6             0            371          boot.ini BAT terlooMaple.rtf ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 6             0            512          BOOTSECT.DOS terlooMaple.rtf ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 34            0            0            CONFIG.SYS S terlooMaple.rtf ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? NOTE: The question mark (?) can represent any character. </li> Run the following query:

<pre class="fixed_text">select LEN(FileName) as filelength from OPENQUERY(P2, 'c:\*.*') as av

Notice that this query returns 261 for all of the rows instead of the real length of the string.</li></ol>

Additional query words: meaningless characters

Keywords: kbbug kbprovider kbpending kbvs2002sp1sweep KB321909

-

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

© Microsoft Corporation. All rights reserved.