Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 914489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:43:35+00:00 2026-05-15T17:43:35+00:00

I was looking for any suggestion or a good approach to handle messages between

  • 0

I was looking for any suggestion or a good approach to handle messages between the data & application tier, what i mean with this is when using store procedures or even using direct SQL statements in the application, there should be a way the data tier notifies upper layers about statement/operation results in at least an organized way.

What i commonly use is two variables in every store procedure:

@code INT,
@message VARCHAR(1024)

I put the DML statements inside a TRY CATCH block and at the end of the try block, set both variables to certain status meaning everything went ok, as you might be thinking i do the opposite on the catch block, set both variables to some failure code if needed perform some error handling.

After the TRY CATCH block i return the result using a record:

SELECT @code AS code, @message AS message

These two variables are used in upper tiers for validation purposes as sending messages to the user, also for committing o rolling back transactions.

Perhaps i’m missing important features like RAISERROR or not cosidering better and more optimal and secure approaches.

I would appreciate your advices and good practices, not asking for cooks recipes there’s no need, just the idea but if you decide to include examples they’d be more than welcome.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:43:35+00:00Added an answer on May 15, 2026 at 5:43 pm

    The generally accepted approach for dealing with this is to have your sproc set a return values
    and use raise error as has been previously suggested.

    The key thing that I suspect you are missing is how to get this data back on the client side.

    If you are in a .net environment, you can check for the return value as part of the ado.net code. The raise error messages can be captured by catching the SqlException object and iterating through the errors collection.

    Alternatively, you could create and event handler and attach to the connection InfoMessage event. This would allow you to get the messages as they are generated from sql server instead of at the completion of the batch or stored procedure.

    another option which I wouldn’t recommend, would be to track all of the things you care about into a XML message and return that from the stored proc this gives you a little more structure then your free text field approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for any recommended validation frameworks, or patterns for an N-tier client application,
I am looking for any tip or guidance to develop an application like cam
I am looking for a good tutorial on XML pull processing (e.g. StAX) using
I am looking for a solution on the following issue. Any suggestions will be
I'm looking for the best (free/cheap) international weather PHP API out there. Any suggestions?
I'm looking for suggestions as well as any benchmarks or observations people have. We
im looking for any information about a builtin algorithm in opengl es to convert
I'm looking for any beyond basic resources that can help me to be proficient
I am looking for any tips or resources on importing from excel into a
I'm looking for any pointers on how to write a rails web app without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.