Microsoft KB Archive/293911

= SAMPLE: ABParam.exe Passes a BLOB Parameter with Active Template Library =

Article ID: 293911

Article Last Modified on 8/9/2004

-

APPLIES TO


 * Microsoft Visual C++ 6.0 Service Pack 5

-



This article was previously published under Q293911



SUMMARY
The ABParam.exe sample demonstrates how to pass a large binary object (BLOB) as a parameter when using the Active Template Library (ATL) Consumer Templates.

Because the ATL Consumer Templates do not currently allow passing of parameters as BLOBs when using a CDynamicParameterAccessor, the Atldbcli.h header file must be modified to allow this behavior. This sample contains a modified header file, called Atldbcli_new.h, and a simple application that inserts a BLOB value into a SQL Server 7.0 or SQL Server 2000 database by using a parameterized INSERT statement.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

ABParam.exe

Release Date: June 18, 2001

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The ABParam.exe file contains the following files:

To use the sample, modify the connection properties in AtlBlobParam.cpp to reflect your SQL Server server, authentication settings, and database. Then compile the sample and run it. The sample creates a table named &quot;BlobTable&quot; in the database and inserts a single record into it.

Implementation Details
For an OLE DB consumer application to use BLOB input parameters, several requirements must be met:  If the provider does not support writing to the provider's storage object, the consumer application must implement an object that implements the ISequentialStream interface. This is the case with the Microsoft OLE DB Provider for SQL Server (SQLOLEDB).

To implement the consumer storage class, this sample uses the ISSHelper class, which is presented in the following article in the Microsoft Knowledge Base:

190958 SAMPLE: AOTBLOB Read/Writes BLOB Using OLE DB Consumer Template

 The consumer application must bind status, length, and value for the parameter. One problem with the current ATL Consumer Template implementation of CDynamicParameterAccessor is that it does not allow the setting and getting of status and length when binding parameters. The Atldbcli_new.h header file contains modifications to allow binding status and length. The approach used is similar to that described in the following article in the Microsoft Knowledge Base:

264291 SAMPLE: Retrieve and Set the DBSTATUS of Parameters Through the Use of CDynamicParameterAccessorEx

 The consumer application must bind the BLOB parameter as an ISequentialStream object instead of a memory buffer. The ATL Consumer Templates do not bind to ISequentialStream when using CDynamicParameterAccessor. The Atldbcli_new.h file modifies the binding calls to bind to an ISequentialStream object.

When you attempt to use a BLOB parameter with the CDynamicParameterAccessor class without the changes outlined in this sample, the following error code may be returned by the BindParameters function when binding the parameters:

E_OUTOFMEMORY, 0x8007000e, or -2147024882

This error occurs when the BindParameters call attempts to allocate a memory buffer of size 0x7fffffff or greater, because this is the size of the BLOB parameter as described by a call to IColumnsInfo which is performed by the CDynamicParameterAccessor class.

To meet the requirements described above, the following changes have been made to Atldbcli.h in the Atldbcli_new.h header file:
 * GetParamLength and GetParamStatus have been added to the CDynamicParameterAccessor class.
 * The BindParameters function of the CDynamicParameterAccessor class has been modified as follows:
 * The nLengthOffset and nStatusOffset variables have been added to track the current offset to the length and status parts of the current binding.
 * The DBOBJECT* pObject variable has been added to allow binding to a storage object.
 * If the size of the parameter is determined to be more than 1024 bytes, or the type of the parameter is DBTYPE_IUNKNOWN, the pObject variable is initialized to point to a new DBOBJECT structure that will be used to bind to an ISequentialStream object.
 * The Bind call has been modified to include nonzero offsets to status and length variables.

Additional query words: BLOB CDynamicParameterAccessor Parameters ISequentialStream ABParam

Keywords: kbdownload kbbug kbnofix kbconsumer kbfile kbsample KB293911

-

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

© Microsoft Corporation. All rights reserved.