1. Daryl Foster
  2. SnapObjects
  3. Monday, 26 October 2020 06:29 AM UTC


Hi, I'm using the SnapObjects SelectProcedure function in a web api and I want to know how to catch an error that occurs in the stored procedure (from a RAISERROR command in the stored procedure.)  The SelectProcedure works ok and fills my model with data when I call it and it works normally, but when the stored procedure raises an error the model is null.  I guess I can tell that the stored proc has failed if the model is null, but I want to get the details from the RAISERROR in the stored procedure similar to how I would with sqldbcode and sqlerrtext in Powerbuilder.

Are there any properties or methods on the DataContext that can give me sqldbcode and sqlerrtext equivalents?

Accepted Answer
Daryl Foster Accepted Answer Pending Moderation
  1. Wednesday, 28 October 2020 06:07 AM UTC
  2. SnapObjects
  3. # Permalink

Thanks Logan, I was using version 2.0, I've now upgraded to version 2.1.  I haven't tried the beta version.

I think I have resolved my issue for now, even with version 2.0.  Part of my issue was that my stored procedure had a SELECT statement before the RAISERROR or THROW.  If I remove that SELECT,  RAISERROR just returns a null object, I can't get it to throw an exception in my C# code at all, but THROW in the stored procedure will throw an exception in my C# code as long as I don't have an earlier SELECT statement, so I will just make sure I use THROW in my stored procedures.

When there is a SELECT statement before either the RAISERROR or THROW in the stored procedure C# seems to ignore it.

Comment
There are no comments made yet.
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 27 October 2020 10:34 AM UTC
  2. SnapObjects
  3. # 1

Hi Daryl,

If the database has an error thrown by RAISERROR, the application will throw an exception.

You can use try... catch (Exception e) to catch the exception, the error message is obtained in e.Message.

Regards,

Logan

Comment
  1. Daryl Foster
  2. Tuesday, 27 October 2020 10:52 AM UTC
Thanks Logan, the stored proc had an error thrown with RAISERROR but the call to SelectProcedure in my C# didn’t throw an exception, it just returned a null object. I also tried throwing the error with THROW in the stored proc with the same result. If I call the SelectProcedure with an invalid stored procedure name the C# throws an exception as expected. The database is MS SQL Server.
  1. Helpful
  1. Logan Liu @Appeon
  2. Tuesday, 27 October 2020 15:35 PM UTC
Hi Daryl,

Are you using the latest NuGet packages? Have ever tried 3.0.0-beta?

If this issue still exists, please report a bug in the Appeon Standard Support at https://www.appeon.com/standardsupport/.

Regards,

Logan
  1. Helpful
  1. Daryl Foster
  2. Wednesday, 28 October 2020 06:08 AM UTC
Thanks Logan, see my reply above.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.