6

I wrote stored procedure witch sometimes RAISERROR(). I execute it through the entity framework like:

using( MyModelEntities conn = new MyModelEntities() ) {
    conn.MyStoredProcedure(input_p, output_p);
}

Stored procedure:

create procedure dbo.MyStoredProcedure(
    @input   nvarchar(255),
    @output int out
)
as
begin
    ...
        RAISERROR (N'My Exception....', 10, 1);
    ...
end
go

Is there any opportunity to get information about error?

3 Answers 3

4

In sql server exception level 1 to 10 are informational and does not raise error back to your application.

change Level in between 11 to 16 to raise error from the SP.

Sign up to request clarification or add additional context in comments.

Comments

2

Can this just be put into a try/catch with the exception displayed? Or maybe you could try going into debug mode?

2 Comments

Btw. I was too fast... RAISERROR is not returning exception. Only Sql Server Erorrs... So how can I handle my Custom errors?
Are you catching an instance of SqlException in your Try/Catch block, and using its Messsage or Errors properties?: (msdn.microsoft.com/en-us/library/…)
0

Here is how I handle this:

create procedure dbo.MyStoredProcedure(
    @input   nvarchar(255),
    @output  text out
)
as
begin
    ...
      SELECT @message = convert(varchar, getdate(), 108) + ': My Exception....'
      SET @output = CAST(@message AS text) -- send message to c#/.net
      RAISERROR(@message,0,1) WITH NOWAIT  -- send message to SQL Server Management Studio
    ...
end
go

Then on the C#/EF side:

public string CallMyStoredProcedure(string input)
{
    var outputParameter = new ObjectParameter("output", typeof(string));
    EntityContext.MyStoredProcedure(input, outputParameter);
    return (string)outputParameter.Value;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.