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

  • Home
  • SEARCH
  • 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 167705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:19:22+00:00 2026-05-11T12:19:22+00:00

We have a large application mainly written in SQL Server 7.0, where all database

  • 0

We have a large application mainly written in SQL Server 7.0, where all database calls are to stored procedures. We are now running SQL Server 2005, which offers more T-SQL features.

After just about every SELECT, INSERT, UPDATE, and DELETE, the @@ROWCOUNT and @@ERROR get captured into local variables and evaluated for problems. If there is a problem the following is done:

  • error message output parameter is set
  • rollback (if necessary) is done
  • info is written (INSERT) to log table
  • return with a error number, unique to this procedure (positive if fatal, negative is warning)

They all don’t check the rows (only when it is known) and some differ with more or less log/debug info. Also, the rows logic is somethimes split from the error logic (on updates where a concurrency field is checked in the WHERE clause, rows=0 means someone else has updated the data). However, here is a fairly generic example:

SELECT, INSERT, UPDATE, or DELETE  SELECT @Error=@@ERROR, @Rows=@@ROWCOUNT IF @Rows!=1 OR @Error!=0 BEGIN     SET @ErrorMsg='ERROR 20, ' + ISNULL(OBJECT_NAME(@@PROCID), 'unknown')                                 + ' - unable to ???????? the ????.'     IF @@TRANCOUNT >0     BEGIN          ROLLBACK     END      SET @LogInfo=ISNULL(@LogInfo,'')+'; '+ISNULL(@ErrorMsg,'')+         + ' @YYYYY='        +dbo.FormatString(@YYYYY)         +', @XXXXX='        +dbo.FormatString(@XXXXX)         +', Error='         +dbo.FormatString(@Error)         +', Rows='          +dbo.FormatString(@Rows)      INSERT INTO MyLogTable (...,Message) VALUES (....,@LogInfo)      RETURN 20  END 

I am looking into replacing how we do this with the TRY-CATCH T-SQL. I’ve read about the TRY…CATCH (Transact-SQL) syntax, so don’t just post some summary of that. I’m looking for any good ideas and how best to do or improve our error handling methods. It doesn’t have to be Try-Catch, just any good or best practice use of T-SQL error handling.

  • 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. 2026-05-11T12:19:23+00:00Added an answer on May 11, 2026 at 12:19 pm

    You should read this:

    http://www.sommarskog.se/error-handling-I.html

    I can’t recommend that link highly enough. It’s a bit long, but in a good way.

    There’s a disclaimer at the front that it was originally written for SQL Server 2000, but it covers the new try/catch error handling abilities in SQL Server 2005+ as well.

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

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Does the /interactive switch buy you what you want? "Use… May 11, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer No you can't, you would have to dereference it: SetOponent(… May 11, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer This is a feature coming in Silverlight 3 - due… May 11, 2026 at 6:02 pm

Related Questions

In the company that i work, we develop all the GUI in C#, but
Before I start with the real question, let me just say that I might
We have a relatively large application that is strongly tied into Firebird (stored procedures,
I have a large Silverlight application, and we have decided to redesign the whole

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.