2

I'm having some trouble with my error handling in my ASP.NET MVC 2 application. I'm using LINQ to SQL for ORM and am only using Stored Procedures for getting and changing data in the SQL Server. My SP use TryAndCatch blocks, and raiseerrors. But when calling a SP in my client application that raises an error the clientapp just goes on. My goal is to get the clientapp to go to the catch block and there retrieve the error message that the SP raised. Is this possible? If so, could someone be so kind and give me some hints?

Tim

This post asked pretty much the same question, but the answer didn't help to much :/

How do you get full error information for a stored procedure error out of LINQ-to-SQL or SQL Server?

1 Answer 1

3

Modify your catch statement to accept an Exception argument:

try
{
    var result = db.MySProc().ReturnValue;
}
catch (SqlException ex) // specific exception
{
    // handle exception
    Console.WriteLine(ex.Number);
}

Take a look at the MSDN topic for more information: try-catch (C# reference).

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

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.