On updating a row which has been newly inserted into a table, whether through an OLEDB rowset or an ActiveX Data Objects (ADO) recordset, the following error may occur:
(0x80040e21, DB_E_ERRORSOCCURRED) Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
This error occurs when the following conditions are met:
- There is a connection to SQL Server through the OLE DB Provider for ODBC drivers (MSDASQL).
- The recordset is created by selecting from a SQL Server database table.
- The recordset uses server-side cursors.
- One of the columns in the recordset is the primary key for the table.
- There is an insert trigger on the table which inserts rows into some database object.
- The AddNew and Update methods are used to add a new row to the table.
- Update is called again to update a row before the recordset has been scrolled using FetchNext, FetchFirst, and so on.
To prevent this error from occurring, do any of the following:
- Use client-side cursors (by setting the ADO recordset Cursor Location property to adUseClient).
- Remove the insert trigger from the source table.
- Put the following line at the beginning of the trigger code.
- Use SQLOLEDB rather than MSDASQL, and set the "Change Inserted Rows" property of the Recordset object to true before opening the recordset:
pRs.Properties.Item("Change Inserted Rows") = True
- Remove the primary key from the table.
- After calling Update the first time to insert the new row in the table, scroll the recordset using methods like MoveNext and MovePrevious before calling Update again.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.