0

In my SP (Sql Server 2005) I'm raising an error using

Raiserror ('No Records Fetched' , 16 ,1)

I want to catch this particular error in ASP.NET.. how do I do it ?

2 Answers 2

1

This ought to do it:

catch(SqlException ex) {
    if(ex.Errors.Count > 0 && ex.Errors[0].Message == "No Records Fetched" && ex.Errors[0].Class == 16) {
        // your error
    }
}

However, the errors collection may also contain low-severity print statement messages and other junk from previous statements. It's up to you whether you want to write more sophisticated filtering code to eliminate them.

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

Comments

0

Whilst Christian Hayter's answer is correct, an alternative would be to use sp_addmessage to create your own customer error number which relates specifically to this problem. This would save you having to parse the error message.

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.