I have a stored procedure that gives a friendly enough error that I want to show to the users but when I call it from .net it comes out twice. When I call the proc from sql server management studio it only comes out once.
Here is a cutdown version of the stored proc:
ALTER PROC [Production].[spDoSomething] (
@PassedID int)
AS
BEGIN
DECLARE @ErrorString nvarchar(500);
BEGIN TRY
...
RAISERROR('Bad things are happening.', 11 /*severity*/, 1 /*state*/);
...
END TRY
BEGIN CATCH
SET @ErrorString = 'Error found:' + ERROR_MESSAGE();
PRINT @ErrorString;
RAISERROR(@ErrorString, 11 /*severity*/, 1 /*state*/);
END CATCH
END
I call this in some c# code using ExecuteNonQuery()
of a System.Data.SqlClient.SQLCommand
object then I catch a System.Data.SqlClient.SQLException
but the Message contains
"Error: Found Bad things are happening.\nError Found: Bad things are happening."
Does anyone know a reason why it comes out twice?
This is on sql server 2008 and .net 3.5