How to: Bulk Copy Data Using IRowsetFastLoad (OLE DB)
The consumer notifies SQLOLEDB of its need for bulk copying by setting the SQLOLEDB provider-specific property SSPROP_ENABLEFASTLOAD to VARIANT_TRUE. With the property set on the data source, the consumer creates a SQLOLEDB session. The new session allows the consumer access to IRowsetFastLoad.
A complete sample is available that illustrates the use of IRowsetFastLoad for bulk copying of the records into a table. In this sample, 10 records are added to the table IRFLTable. You need to create the table IRFLTable in the database.
The complete sample code is in the file BulkCopyRecords.cpp. You can download an archive containing the sample from the SQL Server Downloads page on MSDN.
This sample was developed using Microsoft Visual C++ 2005.
|When possible, use Windows Authentication. If Windows Authentication is not available, prompt users to enter their credentials at run time. Avoid storing credentials in a file. If you must persist credentials, you should encrypt them with the Win32 crypto API.|
Establish a connection to the data source.
Set the SQLOLEDB provider-specific data source property SSPROP_ENABLEFASTLOAD to VARIANT_TRUE. With this property set to VARIANT_TRUE, the newly created session allows the consumer access to IRowsetFastLoad.
Create a session requesting the IOpenRowset interface.
Call IOpenRowset::OpenRowset to open a rowset that includes all the rows from the table (in which data is to be copied using bulk-copy operation).
Do the necessary bindings and create an accessor using IAccessor::CreateAccessor.
Set up the memory buffer from which the data will be copied to the table.
Call IRowsetFastLoad::InsertRow to bulk copy the data in to the table.