BUG: ATL OLE DB provider returns incorrect length for variable-length string field (321909)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • 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:
  1. In TransferData method call, locate line 7329, which appears as follows:
    if(pBindCur->dwPart & DBPART_LENGTH )
    					
  2. 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.
    					
  3. 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)
     ......
  4. 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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Use the ATL OLE DB Provider Wizard to create a provider, and then accept all of the default options.
  2. Use this provider to create a SQL Server linked server, and then click Run In-Proc for the provider option.
  3. Run the following query:

    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.
  4. Run the following query:

    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.

Modification Type:MinorLast Reviewed:9/13/2005
Keywords:kbvs2002sp1sweep kbbug kbpending kbProvider KB321909 kbAudDeveloper