M mttc Apr 12, 2008 #1 error that occur in StoredProcedure it's cause exception or not? and when I need to use with @@error?
error that occur in StoredProcedure it's cause exception or not? and when I need to use with @@error?
M Misbah Arefin Apr 13, 2008 #2 yes errors with a certain severity level will throw exceptions in your code try this in your stored proc RAISEERROR(N'This is a message %s %d', -- message text 16, --severity 1, --state N'number', --first argument 5); --second argument and in your code you can get this error message in the SqlException object try { ExecuteSP(); } catch(SqlException ex) { Console.WriteLine(ex); //ex.Message will have the message text you used in raiseerror } for details on RAISEERROR check the following url http://msdn2.microsoft.com/en-us/library/ms177497.aspx note: not all errors in SP / RAISEERROR throw exceptions in code... check the severity levels to confirm
yes errors with a certain severity level will throw exceptions in your code try this in your stored proc RAISEERROR(N'This is a message %s %d', -- message text 16, --severity 1, --state N'number', --first argument 5); --second argument and in your code you can get this error message in the SqlException object try { ExecuteSP(); } catch(SqlException ex) { Console.WriteLine(ex); //ex.Message will have the message text you used in raiseerror } for details on RAISEERROR check the following url http://msdn2.microsoft.com/en-us/library/ms177497.aspx note: not all errors in SP / RAISEERROR throw exceptions in code... check the severity levels to confirm