BUG: Incorrect Number of Rows Inserted Using MS ODBC Driver and Stored Procedure on SQL Server (293901)
The information in this article applies to:
- Microsoft ODBC Driver for SQL Server 2000.80.194
- Microsoft ODBC Driver for SQL Server 3.7
- Microsoft Data Access Components 2.0
- Microsoft Data Access Components 2.1
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
- Microsoft Data Access Components 2.7
This article was previously published under Q293901 SYMPTOMS
If you use the Microsoft ODBC Driver for SQL Server to execute a stored procedure that inserts multiple rows into a SQL Server table, an inconsistent number of records may be inserted.
This problem can occur when all of the following conditions are met:
- You are using the Microsoft ODBC Driver to connect to SQL Server.
- The stored procedure that inserts records into the table does not specify SET NOCOUNT ON.
- You do not call SQLMoreResults to extract all tokens from SQL Server.
- You use SQLSetEnvAttr to programmatically set ODBC versions to SQL_OV_ODBC3 instead of SQL_OV_ODBC2.
- SQL_ATTR_AUTOCOMMIT is set ON.
CAUSE
When you do not specify SET NOCOUNT ON in your stored procedure, SQL Server returns a token for every INSERT statement, and if you do not extract all the returned tokens by using SQLMoreResults, you will get inconsistent results.
RESOLUTION
You can work around this problem in the following ways:
- Specify SET NOCOUNT ON in the stored procedure.
- Call SQLMoreResults until you get SQL_NO_DATA to extract all tokens from SQL Server.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 12/5/2003 |
---|
Keywords: | kbbug kbDriver kbnofix KB293901 |
---|
|