Stored Procs - The Best Way to Transfer Messages Back to a User Application

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.

+5
source share
14 answers

, - "", , , - FK.

"", . RAISERROR ( " XYZ!" ), . , , , // .

+6

RAISERROR, , . , , , .

OUT ? , . API, OUT.

+4

2 . , . , , .

+2

, ? Anywho...

Bad Thing, . , , . . / Jens K . , , , .

+1

, , . , .

,

  • .

.

+1

, procs Business Related, , , / -.

(). RAISEERROR (, , , ). , , , .

, .

0

, , - , .

, . - , Error, , . , .

, RAISERROR.

0

raiseerror , , ( Java JDBC). XML-, JDBC, . ok, alert, . , , , . , . punt, .

0

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 , .

0

"" , , - , .

- , . , -.

, , / , , 90 . , , , , .

0

.

0

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
0

/ , - .

raiseerror , , / , " " , .

, , .. "" , , /: P

-1

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)

-2
source

All Articles