Microsoft KB Archive/302423

= BUG: Execution of RAISERROR(@@ERROR) Causes Access Violation =

Article ID: 302423

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft SQL Server 7.0 Standard Edition

-



This article was previously published under Q302423



BUG #: 101802 (sqlbug_70)

BUG #: 54124 (sqlbug_70)



SYMPTOMS
An access violation (AV) may occur when you execute this code: RAISERROR(@@ERROR, 1,1) A message similar to the following may be returned to the client application:

ODBC: Msg 0, Level 19, State 1 SqlDumpExceptionHandler: Process 9 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process. Connection Broken

The SQL Server error log may contain entries similar to the following:

'On SQL Server Service Pack 3 (7.00.961)' Short Stack Dump 0x006d0084 Module(sqlservr+2d0084) (Blob::DeleteForMaint+28b) 0x0040f487 Module(sqlservr+f487) (CMsqlExecContext::ExecuteStmts+11b) 0x0040ef35 Module(sqlservr+ef35) (CMsqlExecContext::Execute+16b) 'On SQL Server Service Pack 2 (7.00.842)' Short Stack Dump 0x00720072 Module(sqlservr+320072) (BackupFileDesc::VerifyCreatability+ad) 0x004145f1 Module(sqlservr+145f1) (CMsqlExecContext::ExecuteStmts+11a) 0x0041409f Module(sqlservr+1409f) (CMsqlExecContext::Execute+16a) 'On SQL Server Service Pack 1 (7.00.699) and Golden (7.00.623)' Short Stack Dump 0x00720072 Module(sqlservr+320072) (SQL_CONFIG_INFO::Dump+224) 0x00414bee Module(sqlservr+14bee) (CMsqlExecContext::ExecuteStmts+11b) 0x0041463d Module(sqlservr+1463d) (CMsqlExecContext::Execute+16b)



WORKAROUND
To work around this behavior, return the value in @@ERROR by using a return value.

For example: Create proc ReturnErrorCode as declare @err int --Local variable to hold Error value. --execute some statement set @err = @@ERROR --This sets @@ERROR back to 0. if @err != 0 RETURN @err

go DECLARE @i int

exec @i = ReturnErrorCode --Check value of @i to see if procedure was successful.



STATUS
Microsoft has confirmed this to be a problem in SQL Server 7.0.



MORE INFORMATION
You can only use variables and constant values as parameters to the RAISERROR function, expressions and other functions are not allowed. In earlier versions of SQL Server the @@functions are referred to as global variables; however @@functions are not variables and @@functions does not have the same behavior as variables. The @@functions are system functions, and their syntax usage follows the rules for functions.

Additionally, an attempt to raise an error number lower than 13000 causes this error message to occur:

Server: Msg 2732, Level 16, State 1, Procedure a, Line 5 Error number %ld is invalid. The number must be from 13000 through 2147483647

Keywords: kbbug kbpending KB302423

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.