PRB: Errors Not Returned When Stored Procedure Statement Fails (253240)
The information in this article applies to:
- Microsoft Active Server Pages
- Microsoft Data Access Components 2.0
- Microsoft Data Access Components 2.1
- Microsoft Data Access Components 2.1 (GA)
- Microsoft Data Access Components 2.1 SP1
- Microsoft Data Access Components 2.1 SP2
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
- Microsoft SQL Server 6.5
- Microsoft SQL Server 7.0
This article was previously published under Q253240 SYMPTOMS
When executing a stored procedure with multiple queries (SELECTs, INSERTs and UPDATEs), the ActiveX Data Objects (ADO) errors collection appears not to be populated after an error occurs in the stored procedure. The stored procedure might also not return values from its RETURN statement.
CAUSE
The SQL Server OLE DB provider provides more accurate information (than ODBC) to the caller about what happened in the procedure. Each SQL statement within a stored procedure returns a "result," either a count of rows affected or a result set. You can walk through these result sets in ADO using the NextRecordset method on the Recordset object.
The SQL Server ODBC provider, however, does not provide information about the results of individual SQL statements within a stored procedure. The only result that comes back from a stored procedure execution is the result of the SELECT statement, if it has one. This is why this problem may not manifest with ODBC.
In both cases, return values from the stored procedure may not be returned.
RESOLUTION
To resolve this problem, make sure that the SET NOCOUNT ON statement comes before any other SQL statements in the stored procedure, as in the following:
CREATE PROCEDURE TestProc
AS
SET NOCOUNT ON -- This is off by default
SELECT au_lname FROM Authors
RETURN 0
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 12/3/2003 |
---|
Keywords: | kbCodeSnippet kbDatabase kberrmsg kbprb KB253240 |
---|
|