How to Commit transaction even the trigger fails?

Hi Everyone,
I got a situation here, i have two tables and a trigger. A main table and a log table. Whenever  a change happens in the main transaction ,   a log details will be inserted into the log table.
Am using sql server 2000 and "For insert,update,delete" in one trigger. 
I am in need of commiting the original transaction even if the trigger fails. I mean the main table is so important for me, so all the transaction should commit in the main table no matter if some transactions details missed in the log table.
I tried with
begin try
-- statement
end try
begin catch
commit transaction
end catch.
But it doesnt works. My insert fails whenever the trigger fails. i want the transaction should continue even if the trigger fails...
Pls suggest me how to do it.. Thanx for your help

If the trigger action is optional, it should not be in a trigger. The idea of a trigger is that it is part of the statement, so if the trigger fails, the statement fails.
As for what your alternatives are, it depends on which version on SQL Server you are using. You first say SQL 2000, but then you discuss TRY CATCH which was added in SQL 2005.
What always works is to have a separate process that scans the main table for changes and the update the log. It can be difficult to identify the changes, though. It helps if you are on SQL 2008 where you can use Change Tracking.
Another solution is to put a message on a Service Broker queue in the trigger, and then you have an activation procedure where you perform the operation with the log table. Of course, the SEND operation may fail, and you are back on square one. But it may
be less likely that this fails than producing the log operation if this is complex and fragile.
Also, a possibility is to add this statement to the trigger:
SET XACT_ABORT OFF
In this case, some errors in the trigger will not cause the statement to fail. More precisely, not errors that under normal circumstances terminates only the current statement, for instance PK violations, NOT NULL errors. There are still
plenty of errors that always aborts the batch and rolls back the open transaction. For instance, conversion errors often rolls back the transaction. Note that SET XACT_ABORT only has effect in SQL 2005 or later.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • How to insert the data even the trigger returned null

    Hi Gurus,
    I have a question regarding on how to insert the record even the condition being used by a "before insert trigger" returned null.
    The scenario is:
    2 tables have the same structure:
    Table A (Name varchar2 (100), No Number)
    Table B (Name_1 varchar2 (100), No Number)
    A script is using to load the data into table A daily, and a “before insert trigger” is being used to get the value for A.Name = B.Name whenever the condition A.No equals to B.No.
    If the B.No exists, then the trigger work fine, otherwise the records will be rejected, this is not the way we wanted, so I just wonder, is there any way to load all the data to the other fields but still using this trigger ?
    Thanks,
    Tran

    Either amend the select in the trigger that gets the name value to not raise a NO_DATA_FOUND exception (e.g. change "select name..." to "select min(name)..." ) or handle the NO_DATA_FOUND exception in an exception handler.
    e.g.
    EXCEPTION
      WHEN no_data_found THEN
        :new.name = 'where the streets have no name';

  • Transaction with the server failed error 405

    HI,
    Thanks in advance.
    We are working on the MDM service provided by apple using the iPCU and have configured the server with valid certificate. But still we notice some other error. Please help us to resolve this.
    Error:
    (Error) MDM: Cannot Authenticate. Error: NSError:
    Desc   : A transaction with the server at failed with the status 405.
    US Desc: A transaction with the server at has failed with the status 405.
    Domain : MCHTTPTransactionErrorDomainCode   : 23001
    Type   : MCFatalErrorParams : ("https://xxxxx.xxx.com/Checkin.aspx",    405)
    (Error) MC: Cannot install MDM com.xxx.mdm.mdm3. Error: NSError:
    Desc   : The payload com.xxx.mdm.mdm3 could not be installed.
    Sugg   : A transaction with the server at https://xxxx.xxx.com/Checkin.aspx has failed with the status 405.
    US Desc: The payload com.xxx.mdm.mdm3 could not be installed.
    US Sugg: A transaction with the server at https://xxxx.xxx.com/Checkin.aspx has failed with the status 405.
    Domain : MCInstallationErrorDomainCode   : 4001
    Type   : MCFatalErrorParams : (    "com.xxx.mdm.mdm3")...Underlying error:NSError:
    Desc   : A transaction with the server at https://xxxxx.xxx.com/Checkin.aspx has failed with the status 405.
    US Desc: A transaction with the server at https://xxxxx.xxx.com/Checkin.aspx has failed with the status 405.
    Domain : MCHTTPTransactionErrorDomainCode   : 23001
    Type   : MCFatalErrorParams : (    "https://xxxxx.xxx.com/Checkin.aspx",    405)

    But in 2005 B I did the same without using license file.
    Moreover, I can access the other machine's(Server) Companies from different SAP B1 server by using change Server on Choose Company Screen.
    But If I install the client on a system, I am not able to access the companies.
    Is it mandatory to have License to install the Client of a server?
    Is it new guideline in 2007 or was it already exist in previous versions.

  • After I updated my phone I lost all my pictures and the new apps I downloaded. I would really love my pictures back does anyone know how? It said that the backup failed during the process. Is it all lost?

    I went to update my phone and after the update I recieved a message that it failed and that the back up failed. I had to restore my phone to stock. I just want to know if there was a possibility to get my pictures back. I tried to get my phone to restore from my last back up but it wouldn't do that either. Does anyone have any ideas. I am really only worried about my pictures and videos I had a couple hundred and they were important.

    Thank you. I have been reading about a lot of these occurances and many people have been able to get their pictures back through iexplorer however I am unable to. The error number I got was 50 or something like that. I have a feeling I will not be able to get the pictures back because it said the backup failed after the update failed.

  • How to commit data at the end of a bounded task flow

    Hi all,
    I am using JDev 11.1.1.0.2.
    I have this situation
    1) A page with a button that goes to a task-flow to insert data (property data-control-scope set to shared and property transaction set to requires-transaction as suggested in http://www.oracle.com/technology/products/jdev/tips/fnimphius/cancelForm/cancelForm_wsp.html?_template=/ocom/print )
    2) At the end of this task-flow a I have a TaskFlowReturn (property End Transaction set to commit)
    When I click the button associated to this TaskFlowReturn, I return to the first page (described in 1) ), but the data I have just inserted are only submitted, but not committed.
    What's the problem?
    Any suggestions?
    Thanks
    Andrea

    Hi,
    if you set the return activity to commit the transaction then this is done. I don't see why rollback should work but commit doesn't
    Frank

  • WAR - how to continue compiling even when compile fails for some jsp's

    i am trying to pre-compile all my jsp's and find out all the compilation
              errors in all the jsp's..
              i am defining a war app and i am making the weblogic server to precompile
              the jsp's.. i control this from web.xml
              the problem is
              weblogic starts compiling the jsp's and when it hits the first error it
              bails out.. i doesn't precompile the rest of the jsp's..
              how do i make weblogic server to continue compiling the rest of the jsp's??
              anyone??
              

    You sure can run a Windows Form and while it is visible, run code in the Powershell script, and communicate the information from the 'main' script  to the form.
    To do this you need create a separate Powershell runspace and dependent on situation either use shared memory and timer in the form or delegates to directly call form elements
    Please check my article at codeproject for extensive journey of using all core Windows Forms, WPF, Selenium with Powershell for tasks which often require various option prompts.
    http://www.codeproject.com/Articles/799161/Dealing-with-Powershell-Inputs-via-Basic-Windows-F
    You find there over 40 common Windows form patterns  ( prompts, grids, check/radio boxes, progress bars of many forms, tree views, item lists, passwords, tool tips, system tray widgets, browser controls, examples of using p/invoke, hosting custom controls,
    dealing with selenium webdriver, dealing with selenium-unfriendly file upload dialogs etc. ) all covered there - working code for every example is provided, and the code is hosted on github.
    Routine daily devops tasks of executing Powershell scripts in a complex environment suddenly become a less challenging task. Web scraping becomes more fun

  • How do I get past the "installation failed" notice?

    My computer is on Cable One, so it's ALWAYS on. I can't close it as requested, and Flash Player won't install the new version unless I close it. Now what? I'm not very computer savvy; I know just enough to get in trouble.

    Hi, well that sounds good. When you went to that test site, were you able to see the Flash logo moving?
    The Shockwave you say is Enabled, is this the Shockwave Flash Object? If so then your Version of Flash Player 10.1.82.76 is the latest version.
    Are you having any problems viewing videos or Flash Content?
    Thanks,
    eidnolb

  • Failed to Commit transaction!

    Hi!
       when i attempt to add any marketting document, an error is thrown stating "Failed to Commit transaction" and the documents remain in Add mode, But the Document is posted actually. When Browsing back to fetch the last document posted it is there. but still i am getting this error. have any one faced similar situation?
    kindly help me!
    TIA,
    Shiva.
    Edited by: Darius Heydarian on Mar 26, 2008 5:00 PM.

    No Suda! the DB dose'nt have any addons or any stored procedure. it is a new DB which i have created for testing purpose.
    Kindly say me is there any other thing which does this?
    Will that affect any of the postings?
    Thk u,
    Shiva
    Edited by: Shivanesh Dhanasekar on Feb 26, 2008 2:54 PM

  • Trigger fails when variable used in WHERE statement

    I have a trigger that works when the following statment is in it:
    SELECT custcall.callrkey into v_callrkey from custcall where custcall.servno = 152345;
    But the trigger fails when I attempt to use a variable in the where statement as follows.
    SELECT custcall.callrkey into v_callrkey from custcall where custcall.servno = :new.servno ;
    Even though I have verified that the value of :new.servno is set to 152345 by outputting the value . That is the only difference between the working version and the non-working version. By not working I mean that the email which is to be sent by the trigger is not received.
    Can anyone give me any ideas of how I could troubleshoot this or what might me happening? I'm pretty new to this and
    feel that I'm missing something very simple. My apologies in advance if this has been posted elsewhere. I did spend a lot of time searching the forum before posting.
    This is Oracle 9i.
    Thanks!
    Full code probably not necessary but posted below just in case:
    create or replace
    TRIGGER EMAILNOTIFY_NEW_SR
    AFTER INSERT ON CUSTPROB
    FOR EACH ROW
    DECLARE
    --SMTP Variables
    vreply utl_smtp.reply;
    vreplies utl_smtp.replies;
    mailCONN utl_smtp.connection;
    mailHOST VARCHAR2(64) ;
    --MESSAGE Variables
    mailText VARCHAR2(64);
    mailFROM VARCHAR2(64);
    mailTO VARCHAR2(64);
    mailDATE VARCHAR2(20);
    v_servno number ;
    v_callrkey number ;
    --PROGRAM Variables
    i number;
    BEGIN
    --get some values from the database  
    --set values for variables...
    mailHOST:= '10.35.173.15'; --this will always stay the same 
    mailFROM := 'Facilities_Customer_Service_Center'; --this will always stay the same
    mailTO := '[email protected]';
    SELECT custcall.callrkey into v_callrkey from custcall where custcall.servno = :new.servno  ;
    SELECT TO_CHAR(SYSDATE,'MM/DD/YYYY HH24:MI:SS') INTO mailDATE FROM dual;
    dbms_output.put_line('open_connection');
    dbms_output.put_line('---------------');
    vreply := utl_smtp.open_connection(mailHOST, 25, mailCONN);
    dbms_output.put_line('helo');
    dbms_output.put_line('----');
    vreply := utl_smtp.helo(mailCONN, mailHOST);
    dbms_output.put_line( 'code = ' || vreply.code );
    dbms_output.put_line( 'text = ' || vreply.text );
    dbms_output.put_line('mail');
    dbms_output.put_line('----');
    vreply := utl_smtp.mail(mailCONN, mailFROM);
    dbms_output.put_line( 'code = ' || vreply.code );
    dbms_output.put_line( 'text = ' || vreply.text );
    dbms_output.put_line('rcpt to');
    dbms_output.put_line('----');
    vreply := utl_smtp.rcpt(mailCONN, mailTO);
    dbms_output.put_line( 'code = ' || vreply.code );
    dbms_output.put_line( 'text = ' || vreply.text );
    dbms_output.put_line('open_data');
    dbms_output.put_line('---------');
    vreply := utl_smtp.open_data(mailCONN);
    dbms_output.put_line( 'code = ' || vreply.code );
    dbms_output.put_line( 'text = ' || vreply.text );
    --SMTP ENVELOPE STUFF (In case it is needed later).  
    --utl_smtp.write_data(mailCONN, 'From:'  ||mailFROM     || chr(13));
    -- utl_smtp.write_data(mailCONN, 'To: '||mailTo || chr(13));
    --utl_smtp.write_data(mailCONN, 'CC:      '||mailFROM     || chr(13));
    --utl_smtp.write_data(mailCONN, 'Date:    '||mailDATE     || chr(13));
    --utl_smtp.write_data(mailCONN, 'BCC:     '||mailFROM     || chr(13));
    --THE MESSAGE
    utl_smtp.write_data(mailCONN, 'Subject: '||'Your Facilities Service Request ' ||'(SR '||v_servno||')'|| chr(13));
    utl_smtp.write_data(mailCONN, '');
    utl_smtp.write_data(mailCONN, '');
    utl_smtp.write_data(mailCONN, 'Dear Customer ' || chr(13));
    utl_smtp.write_data(mailCONN, '');
    utl_smtp.write_data(mailCONN, 'This is to inform you of something.' || ' ' ||mailTO|| chr(13) );
    utl_smtp.write_data(mailCONN, 'Please call us with any questions or concerns. ' || '' || chr(13));
    --DEBUG
    utl_smtp.write_data(mailCONN, 'DEBUG: ' || ''|| chr(13));
    utl_smtp.write_data(mailCONN, 'v_Servno ' || v_servno || chr(13));
    utl_smtp.write_data(mailCONN, 'v_callrkey ' || v_callrkey || chr(13));
    --END THE MESSAGE
    dbms_output.put_line('close_data');
    dbms_output.put_line('----------');
    vreply := utl_smtp.close_data(mailCONN);
    dbms_output.put_line( 'code = ' || vreply.code );
    dbms_output.put_line( 'text = ' || vreply.text );
    dbms_output.put_line('quit');
    dbms_output.put_line('----');
    vreply := utl_smtp.quit(mailCONN);
    dbms_output.put_line( 'code = ' || vreply.code );
    dbms_output.put_line( 'text = ' || vreply.text );
    END;

    Justin,
    Thanks for the reply. I'm away for a couple of days but when I get back to this I'm going to follow up on your suggestion about servno. I'm starting to think that the issue isn't with servno but rather that the select query doesn't return anything because the value I'm trying to get is in another table and is not being inserted in time for me to get them. This will be easiy enough to test. To be honest, I don't know very much about how things are being inserted.
    I appreciate your and Tubby's (and Tom's) concerns. Maybe I'll go back to the drawing board next week. But note that I'm not inserting anything with this trigger--only sending an email based on the insert that is happening through an application. So unless I'm really missing it, my email is dependent on the insert but not vice versa. Since my email is absolutely critical but rather jus a courtesy thing, I was taking a pretty laid back attitude about it but it would be good for me to learn a better way.
    Thanks again to all! I'll report back what I find/decide.

  • Commit a statement in  trigger

    i have a trigger on a table like
    create or replace trig_1
    after insert
    ON t1
    referencing new as new old as old
    for each row
    begin
    INSERT INTO t2 VALUES (:new.abd);
    commit;
    end;
    this is working fine when i insert records in the main table with out commit in trigger .But when i place commit in trigger the insert statement fails showing commit exists on the trigger.
    but i need to commit every row as soon as it is inserted

    > Can you give some more information about the material, manufacturing and the like?
    Quality craftsmanship goes into creating a finely balanced round pipe made of the highest grade of lead.
    > Is it possible to get it colored (are there spring-time colors available)?
    No!! <horrified expression>
    It needs to be in harmony with the universe.. and thus is in the only perfect colour suited for a lead pipe. Gray.
    > Is there any maintenance needed?
    Yes, Cleaning the blood and miscellaneous "bits" from it. May I suggest our lead pipe cleaning kit for a mere $29.99?
    > Are you delivering in non-EU countries?
    As long as you pay in good old fashioned US dollars or Euros, it is not a problem.
    > Will this lead pipe do any harm to the owner?
    Only if you neglect the warning that lead pipes should only be used for situations that demand the dedicated, focussed and lovingly application of sheer bloody mindless violence... using the lead pipe of course.
    > Is there a discount if you have more than 500 posts in this forum ;-)
    ROFL!
    :-)

  • Call *.jar inside the trigger (MS SQL)

    Hi!
    I'm just looking around google and can't find any good news.. The problem is: how to call *.jar inside the trigger. Trigger is stored in M$ Server.
    Tnx, if any response! ;)

    What?

  • Begin and Commit Transactions

    I would like to use the begin and commit transaction in stored procedures in T-SQL. I wanted to know if I can put it around a few statements at once and so if there is an error in one of them none of the above statements will save and the procedure will
    terminate. Will this work with just a begin transaction before all the statements and a commit transaction at the end of all the statements and if there is an error nothing will save, or is there more to it?
    thank you
    Debra has a question

    Add also SET XACT_ABORT ON statement in your procedure.
    I suggest you to read this very interesting article Structured
    Error Handling Mechanism in SQL Server 2012, it should tell you everything you need to know.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to group transactions in blue area of Web Interface

    Hello,
    I been trying to figure out how to group transactions in the blue area of the Web Interface similar to 'Go Shopping'.  I tried to search the forum and did not find ana answer.  Is the grouping done by security roles?
    Please let me know.
    Thank you in advance for any assistance.

    Hi,
      In trascn PFCG,under MENU tab,you can change the grouping of transactions as well as  text for the MENU.
    BR,
    Disha.
    Pls reward points for useful answers.

  • Commit not allowed in Trigger  then how to store the values in table

    Hi,
    Database trigger not allowed to COMMIT in it (directly) or in procedure which is calling from the Trigger. it gives error.
    so my question is:-
    1)How Database internally store the INSERT AND UPDATE value in table which is written in procedure without COMMIT?
    2) Is it necessary to write COMMIT in procedure using PRAGAMA AUTONOMOUS TRANSACTION to store inserted or updated value in table?
    Thanks in advance.

    Hi,
    A trigger is designed to be a part of a transaction, not it's end.
    It is like following these steps (not really accurate, but should give an idea):
    1. programA issues INSERT statement on tableA
    2. 'control' goes over to the database
    3. constraint checks happen
    4. the associated triggers on tableA do their work (e.g. fetching a sequence value for a primary key)
    5. 'control' goes back to programA
    6. programA decides if a commit (no error occurred) or a rollback (error case) has to be issued.
    Did this help? Probably not, I'm not happy with what I wrote, but anyway... :)

  • [Execute SQL Task] Error: Executing the query failed with error: "The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION."

    I have an package with source , data flow and destination to execute on begin and commit.
    in the below i have just used for questioning purpose with diagram removing my Data Flow task explaining my problem
    on execution, i get error as
    [Execute SQL Task] Error: Executing the query "COMMIT TRAN DimCompanyCode" failed with the following error: "The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.". Possible failure reasons: Problems with the query, "ResultSet"
    property not set correctly, parameters not set correctly, or connection not established correctly.
    as mentioned , i have checked the ResultSet, parameters , connection establish.. all are fine.
    Kindly advice on what has to be done.
    ShanmugaRaj

    To avoid this error, the RetainSameConnection property should set to 'True' for the Connection Manager - Application_DB.
    Narsimha

Maybe you are looking for

  • My power button is stuck and doesn't turn the phone off or on anymore. Can anyone help?

    My power button is stuck and doesn't turn the phone off or on anymore. Can anyone help?

  • Payment run workflow

    My company has asked me to modify the payment process so that after the payment proposal is generated, a workflow would start. This workflow would route any payments in the proposal that are over $25K to someone for additional approval. Once the appr

  • Best practices for multiple developers?

    I am currently working on a fairly large application. At this time, I have been the only developer on it, so it hasn't been a problem in keeping all of my files up to date or anything. However, I know in the future some new blood will be brought in t

  • How to call the illustrator plugin?

    Is it possible to call the illustrator-plugin through sdk? Could you please provide any samples.

  • Problems starting WLCS server

    when I start the WLCS 3.5 server , it asks me for password and shows weblogic server starting. and later the console seems stuck on the message Initialization Logger for a long time ( over an hour).