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.
MORE INFORMATION
Steps to Reproduce the Behavior
- Use the ATL OLE DB Provider Wizard to create a provider, and then accept all of the default options.
- Use this provider to create a SQL Server linked server, and then click Run In-Proc for the provider option.
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.
- Run the following query:
select LEN(FileName) as filelength from OPENQUERY(P2, 'c:\*.*') as av
Additional query words: meaningless characters
Keywords: kbbug kbprovider kbpending kbvs2002sp1sweep KB321909