Re: Transaction Abort in a trigger SQL 2008, writing to event log

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




Erland,

Thank you for all the information. This is the post where I pulled some of
my logic from in regards to the error info processing. Based on what you said
though, this will not work entirely wither because the transaction could
still be doomed at some point, and need a rollback. You are saying to turn
off xact_abort, would I then need to remove my check for xact_state?

http://blogs.msdn.com/anthonybloesch/archive/2009/03/10/SQL-Server-error-handling-best-practice.aspx

and which I think is still similar to what I was doing, except they are not
creating another transaction within the trigger. Based on what you said
though, there are still some situations where this process will not work

"Erland Sommarskog" wrote:

John Couch (JohnCouch@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
I have seen tons of things out there telling oyu to rollback a
transaction in the catch block of a trigger, capture the error
information and write it out to a table, but I have yet to find a way to
make it work. I have 2 tables, a code table and ServerOption table, and
a trigger on ServerOption that attempts to validate the entry into the
table, and process an error if it occurs. If you make a change from
enterprise manager, I always get the message that the transaction was
aborted in the trigger, and you can't insert into the widnows
application log or even a table. How is this supposed to work???

You can add this command to the trigger:

SET XACT_ABORT OFF

now the trigger will behave like regular code will. That is, normally
XACT_ABORT is off by default, but it's the other round in triggers for
compatibility reasons.

However, there are still some errors that will cause the transaction to
be doomed, in which case you cannot perform any updates until you have
rolled back the transaction.

I note that in the error-handling procedure you do RAISERROR WITH LOG.
Note that this requires sysadmin permission, so if this is to be run by
regular users, this will not work out in its current form. To get it to
work, see this article of mine: http://www.sommarskog.se/grantperm.html.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


.



Relevant Pages

  • Re: Asynchronous Stored Procedure Never Returns - Help?
    ... If you have the Sql Server 2000 or 2005 docs they are thorough and can be ... for Transaction SQL Reference from the drop-down or select a keyword from ... your query in Query Analyzer or Sql Server Management Studio, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: SQL 7 vs. 2000 issue -trigger and nulls
    ... >We're having trouble with a trigger updating some tables. ... course be locked by the current transaction, ... locking data and updating rows when the COMMIT inside the trigger is ... I seriously hope that SQL Server 7.0 simply disregarded these two ...
    (microsoft.public.sqlserver.mseq)
  • Re: on delete set null
    ... > Nun versuche ich das ganze mit einem Trigger zu simulieren (auf SProcs ... SQL Server verlangt ... > CREATE TABLE voranstellen kann, in denen die Tabellen erzeugt werden, ...
    (microsoft.public.de.sqlserver)
  • Re: Handling Script Timeout when invoking ActiveX Object involving ADODB from ASP2.0 pages- SQL Clie
    ... The SQL Client Network Utility on the remote SQL Server 2000 SP3a on Windows ... > This is an example of an Aborted Transaction. ...
    (microsoft.public.sqlserver.clients)
  • Re: Trigger does not seem to fire from front end or enterprise manager
    ... there is no need to even do COMMIT in a trigger. ... > the transaction will be committed as the statement completes. ... > against the inserted and deleted tables inside your trigger code. ... run a profiler trace and you will see what SQL EM submits. ...
    (microsoft.public.sqlserver.programming)