Re: how to catch custom errors raised in SP gracefully?
From: Mary Chipman (mchip_at_online.microsoft.com)
Date: 07/14/04
- Next message: Eliyahu Goldin: "Re: Datasets and business objects"
- Previous message: Cor Ligthert: "Re: RowState"
- In reply to: Bob: "Re: how to catch custom errors raised in SP gracefully?"
- Next in thread: Bob: "Re: how to catch custom errors raised in SP gracefully?"
- Reply: Bob: "Re: how to catch custom errors raised in SP gracefully?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 14 Jul 2004 09:03:04 -0400
Failure to return a result set isn't considered an error (or
InfoMessage) by the server. If you have client-side errors, then the
call never got to the server. Open a Profiler trace to see exactly
what is being passed back and forth between your app and SQLS.
--Mary
On Tue, 13 Jul 2004 14:42:44 -0500, " Bob" <bobatkpmg@yahoo.com>
wrote:
>Hi Mary:
>
>I think this fits my need the best. However, I can't get the event handler
>to throw a new exception, nothing happens. But if I put in
>Console.Writeline, or HttpResponse.Write(), the error message from the event
>argument can be printed out. Do you know why? Here's my code snippet:
>
> private static void OnInfoMessage(object sender, SqlInfoMessageEventArgs
>e) {
> System.Web.HttpContext.Current.Response.Write(e.Message + e.Source +
>e.Errors.Count.ToString() + "Bob");
> throw new Exception("Blah"); //This doesn't throw an exception.
> }
>
>And in my function that actually does the call to the DB, I have this:
>
>....................
> liveCmd.Connection.InfoMessage += new
>SqlInfoMessageEventHandler(OnInfoMessage);
> DataSet ds = DataHelper.ExecuteSelectQuery(liveCmd, string.Empty);
>....................
>
>
>"Mary Chipman" <mchip@online.microsoft.com> wrote in message
>news:s888f0d6njdhdkl5k39qvg20j3qessu4ub@4ax.com...
>> One way to handle it is to use output parameters instead of RAISERROR
>> to handle both server and user-defined errors. Raising exceptions is
>> always expensive, and coding your stored procedures to minimize
>> sending error messages back and forth across the wire is a good idea.
>> Anything that can be handled on the server should be, and the client
>> should get back a clear success/failure message for every operation
>> performed so that it can branch accordingly.
>>
>> --Mary
>>
>> On Tue, 13 Jul 2004 12:44:21 -0500, " Bob" <bobatkpmg@yahoo.com>
>> wrote:
>>
>> >In my stored procedure, I raise an error using RAISERROR. Seems it just
>> >comes out to the .NET code as a SqlException. Is there a way to
>> >differentiate my custom error from the raw SqlExceptions (like table is
>> >missing, FK violation etc), because if I purposely raise an error, I sure
>> >want to handle it differently.
>> >
>> >Thanks
>> >Bob
>> >
>>
>
- Next message: Eliyahu Goldin: "Re: Datasets and business objects"
- Previous message: Cor Ligthert: "Re: RowState"
- In reply to: Bob: "Re: how to catch custom errors raised in SP gracefully?"
- Next in thread: Bob: "Re: how to catch custom errors raised in SP gracefully?"
- Reply: Bob: "Re: how to catch custom errors raised in SP gracefully?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|