开发者

Retrieve error message from SQL Server when using SP in SQL to LINQ

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 retrie开发者_如何学Pythonve 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜