How to Retrieve Info from RAISERROR Function in SQL Server DBLast reviewed: June 21, 1995Article ID: Q120763 |
The information in this article applies to:
- Professional Edition of Microsoft Visual Basic for Windows, version 3.0
SUMMARYThis article explains how to return the error message generated by the RAISERROR function in Microsoft SQL Server. You can use the RAISERROR function in a SQL stored procedure or trigger on a SQL Server database to set a global error number and return a user-defined error message.
MORE INFORMATIONWhen Visual Basic encounters a return value from the RAISERROR function, all it knows is that the "ODBC Call Failed" and Err is set to 3146. The entire ODBC error message is included in the Error$ function. To return the entire error message generated by the RAISERROR function, use the Error$ function in your error trap routine. For example:
If Err = 3146 then MsgBox Error$ End IfNote that this is different from performing a 'MsgBox Error$(Err)' command, which returns only the "ODBC Call Failed" message. Unfortunately, the only way to return the error number set by RAISERROR is to include the number in the error message and parse the return string. However, the Microsoft Access 2.0/Visual Basic 3.0 Compatibility Layer appends the error number to the end of the error message automatically.
Step-by-Step ExampleThe following demonstrates an example stored procedure that generates a RAISERROR message.
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |