Search code examples
sql-servervisual-c++oledbblobread-write

Read and Write data from/to BLOB in MS SQL using Visual C++ and OLE DB


ca you help me? I am looking for example how to insert and get data from BLOB in MS SQL Server 2008. I am using OLE DB and Visual C++. Thanks


Solution

  • There's detailed info on that topic (the write side anyway) here: Sending BLOB Data to SQL SERVER Using IROWSETFASTLOAD and ISEQUENTIALSTREAM.

    Most of the available samples are too simplistic and don’t demonstrate varying data length per row or using ISequentialStream. In this sample, you'll see both techniques in one source file. By default, the sample shows how to use IRowsetFastLoad to send variable length BLOB data per row using in-line bindings. In this case, the in-line BLOB data must fit in available memory. This method has better performance when the BLOB data is a few bytes to a few MB, because there is no additional stream overhead. For larger data, especially where the data is not necessarily all available at once in a block, streaming is a better choice.

    For readback there is background and sample code on MSDN here.

    The SQL Server Native Client OLE DB provider does not retrieve large data from SQL Server until requested to do so by the consumer. The consumer should bind all short data in one accessor, and then use one or more temporary accessors to retrieve large data values as required.