Article ID: 246265 - Last Review: December 5, 2003 - Revision: 3.1 PRB: Slow Inserts Using SQLOLEDB Provider When No Index on SQL7.0 TableThis article was previously published under Q246265 On This PageSYMPTOMS
When you are using the Microsoft Foundation Class Library (MFC) AppWizard or ClassWizard to generate an Active Template Library (ATL) consumer template class wrapper for a table in your database, a class derived from CCommand<CAccessor<TAccessor> > is created. When calling Insert directly on this derived class object to insert a large number of records (for example, 10,000 records), the performance when using SQL OLE DB (SQLOLEDB) Provider is slower than when using ODBC (MSDASQL) Provider if the table does not have a primary key or unique index. CAUSE
When SQL OLE DB Provider is used, and when calling Insert on the derived class object (for example, CRowset::Insert), SQL server treats each insertion as a "positioned" update so that an API cursor (sp_cursor) is generated and used to perform the insert. The insertion statement is not prepared. Without indexing on the table, large numbers of insertions will downgrade the performance considerably. The nonlinear performance degradation is caused by a bug in SQL Server 7.0. For additional information, click the article number below
to view the article in the Microsoft Knowledge Base:
197462
(http://support.microsoft.com/kb/197462/EN-US/
)
Slow Performance Using Cursor Positioned Update If No PK
However, if ODBC provider is used, when the Insert call reaches SQL server, it will prepare the insert statement and then use it to perform the subsequent insertions, which is very efficient.
SQL Server 7.0 profiler can be used to verify the different mechanisms for insertion between these two providers. With SQL OLE DB provider, from the trace log, sp_cursor is created; whereas with ODBC provider, sp_prepare and sp_execute are used when performing insertions. RESOLUTION
If AppWizard- or ClassWizard-generated code is used and the Insert call is made on the derived class object (for example, CRowset::Insert is called), and if you need to perform a large number of insertions on a SQL 7.0 table without a unique index, Microsoft recommends that you use ODBC provider for relatively better performance. However, you may also want to consider the following techniques to improve the performance of large numbers of insertions, depending upon your needs:
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. MORE INFORMATIONSteps to Reproduce Behavior
REFERENCESFor additional information on how to use the IRowsetFastLoad interface, click the article number below
to view the article in the Microsoft Knowledge Base:
246262
(http://support.microsoft.com/kb/246262/EN-US/
)
SAMPLE: Sqlfstin: Speed Up OLEDB Inserts By Using IRowsetFastLoad()
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Thomas Klevmar, Microsoft Corporation. | Article Translations
|

Back to the top
