I would like to know what people think about using RAISERROR in stored procedures to convey user messages (i.e. business related messages, not error messages).
Some of the senior developers at my company use this method and catch a SqlException in our C # code to receive messages and display them to the user. I am not happy with this method and would like to know how other people handle these types of user messages from stored procedures.
, - "", , , - FK.
"", . RAISERROR ( " XYZ!" ), . , , , // .
RAISERROR, , . , , , .
OUT ? , . API, OUT.
2 . , . , , .
, ? Anywho...
Bad Thing, . , , . . / Jens K . , , , .
, , . , .
,
.
, procs Business Related, , , / -.
(). RAISEERROR (, , , ). , , , .
, .
, , - , .
, . - , Error, , . , .
, RAISERROR.
raiseerror , , ( Java JDBC). XML-, JDBC, . ok, alert, . , , , . , . punt, .
RETURN , :
CREATE PROCEDURE checkReturnValue AS BEGIN DECLARE @err AS INT SET @err = 0 IF (rand() < 0.5) BEGIN SET @err = 1 END SELECT * FROM table PRINT @err RETURN @err END
RETURN , .
"" , , - , .
- , . , -.
, , / , , 90 . , , , , .
SQL- .
http://msdn.microsoft.com/en-us/library/ms378108.aspx:
CREATE PROCEDURE GetImmediateManager @employeeID INT, @msg varchar(50) OUTPUT AS BEGIN SELECT ManagerID FROM HumanResources.Employee WHERE EmployeeID = @employeeID SELECT @msg = 'here is my message' END
/ , - .
raiseerror , , / , " " , .
, , .. "" , , /: P
2 :
, , HTTP. , , , , .
So, perhaps the same thing is with the messaging between and above the SQL Server layer. Using text as part of your messaging can make your development more flexible and make your debugging easier. Maybe senior developers are pragmatic, and you might need to be open to put aside your preconceived notions of correctness.
Discuss design choices in essence, not based on concepts of correctness. (There is also a mod in software development)