|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, February 02, 2004 2:40 PM
Points: 15,
Visits: 1
|
|
quote:
Generally, most things can be trapped but the more error trapping is done at the SQL end the bigger the performance hit.
If there are going to be multiple apps hitting a database then I put more error trapping in the database and middle tier. If there are very few apps then I expect the app to take the burden of the error trapping.
Very true! But in a high transaction environment this is not always doable. I guess I've got a general gripe at the way SQL Server/T-SQL handles errors, because for the errors we've been talking about (and without using the trapping you've described), as stored procedure developers, we have to say 'we can trap some errors but not all..' given that, it splits the error trapping duties between the stored proc and the client/middle tier, when what we need at the stored proc level is a comprehensive trapping mechanism. The problem is even more complicated when you add in transaction handling as it's not always clear what was rolled back but that's another thread...
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, June 06, 2012 4:41 AM
Points: 69,
Visits: 37
|
|
The problem I have is that Key violations do not terminate the current batch (unless XACT_ABORT IS set) But ADO does put a client application in the error handler.
My problem with ADO is that I believe that it should only raise an error if the command execution was terminated. SP programmers would have to implement an error reporting using output variables similar to that specified by David above.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, May 22, 2008 2:03 PM
Points: 180,
Visits: 35
|
|
I don't think sp spStaticNoStopOnFirstError can continue if the first query run into an error.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 4:39 PM
Points: 6,260,
Visits: 1,977
|
|
I believe this code:
IF NOT EXISTS (SELECT 1 FROM MyTable WHERE MyField = @Value) BEGIN INSERT MyTable(My Field) VALUES (@Value) RETURN 1 END ELSE BEGIN RAISERROR('My bespoke PK Error',10,1) RETURN 0 END
is still flawed (for The Error trapping purpose that was intended to)
Let's suppose we are in a highly transactional environment and two procedures are executing the same code. On the "Exists" clause both get the "false" but then one of them will insert the PK that maybe the other will try too! Then on the second procedure the insert will raise the "avoided" error to the client. You could have placed a lock but that would be even worse
I would rather rewrite it as:
INSERT MyTable(My Field) VALUES Where MyField <> @Value
IF @@ROWCOUNT = 0 RAISERROR('My bespoke PK Error',10,1)
But in any case, the solution will really be: Microsoft, Please STRUCTURED EXCEPTION HALNDLING!!!!!!
* Noel
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, June 06, 2012 4:41 AM
Points: 69,
Visits: 37
|
|
spStaticNoStopOnFirstError will not continue as the table it refers to does not exist.
However an sp will continue after a unique/primary key violation.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Friday, February 15, 2013 10:33 AM
Points: 976,
Visits: 48
|
|
sunjiulu:
When I execute spStaticNoStopOnFirstError in the pubs database on SQL Server 2000. Both statements in the SP execute even though the first query fails because of a constraint on the table. The second query will succeed the first time it is run. After that it will fail unless you delete all the rows it inserted. In any case, for me both queries run every time I execute this SP.
Are you getting a different reaction when you execute this SP?
Robert W. Marda SQL Programmer bigdough.com The world’s leading capital markets contact database and software platform.
Robert W. Marda SQL Programmer Ipreo
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, June 30, 2011 9:02 AM
Points: 9,
Visits: 82
|
|
Nice, clean, concise examples. Thank you
Regards,
Mike
|
|
|
|