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 8993783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:16:18+00:00 2026-06-15T23:16:18+00:00

We have a back office system that inserts invoice information into an SQL database

  • 0

We have a back office system that inserts invoice information into an SQL database via a MSDTC stored procedure, the application inserts header, then the detail information.

I have set up a CLR trigger on the header table that fires when a record is inserted.

The problem I am having is that the trigger is firing before the COMMIT TRANSACTION meaning that the details information might not be populated, which is required by the process that is triggered. Also if the system fires a ROLLBACK TRANSACTION the trigger has already fired.

I understand that triggers can’t be assigned to a COMMIT, but was wondering if any one had any other thoughts.

I stumbled across a suggested solution for oracle where you create a Materlised View that updates ON COMMIT, and tried to find the TSQL equivalent which is Indexed Views, but had no luck implementing it.

To Summarise:
Is it possible to trigger upon a COMMIT TRANSACTION possibly using Indexed Views ?


CLR Trigger Code

Sends a JMS Message to a queue, to be processed by Sonic ESB.

[Microsoft.SqlServer.Server.SqlTrigger(Name = "InvoiceTrigger", Target = "Table", Event = "FOR INSERT")]
public static void InvoiceTrigger()
{
    //Declare Connection vairables
    string connectionURL, connectionDomain, connectionUser, connectionPassword, connectionQueue;
    //Constant
    connectionUser = "user";
    connectionPassword = "pass";
    connectionQueue = "Queue";
    //Local Environment
    connectionURL = "tcp://IP:2506";
    connectionDomain = "Domain1";

    //Create connection sonic domain
    SonicSend send = new SonicSend(connectionURL, connectionDomain, connectionUser, connectionPassword, connectionQueue);
    
    //Send Test message to pipe
    SqlCommand command;
    SqlTriggerContext triggContext = SqlContext.TriggerContext;
    SqlPipe pipe = SqlContext.Pipe;
    SqlDataReader reader;
    switch (triggContext.TriggerAction)
    {
        case TriggerAction.Insert:
            // Retrieve the connection that the trigger is using
            using (SqlConnection connection = new SqlConnection(@"context connection=true"))
            {
                connection.Open();
                command = new SqlCommand(@"SELECT LSH_LINKCODE, DOC_CODE, LSH_DOCNUM FROM INSERTED;", connection);
                reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    string xml;
                    char cr = (char)13;
                    int i = 0;
                    while (reader.Read())
                    {
                        
                        xml = @"<Invoice action='insert'>";
                        xml += "<LinkCode>" + reader.GetString(0).ToString() + "</LinkCode>";
                        xml += "<DocumentCode>" + reader.GetString(1).ToString() + "</DocumentCode>";
                        xml += "<DocumentNumber>" + reader.GetString(2).ToString() + "</DocumentNumber>";
                        xml += @"</Invoice>";
                        i++;
                        send.testJMSsend(xml);
                        
                    }
                   
                }

                reader.Close();
            }
            break;
    }

}
  • 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-06-15T23:16:19+00:00Added an answer on June 15, 2026 at 11:16 pm

    After helpful comments stating that utilizing the commit in a trigger wasn’t possible.

    I reviewed the ESB process that was kicked off by trigger, the process now queries the data with the passed information, this has fixed my problem due to the fact that the BEGIN TRANSACTION creates a lock on the data the query doesn’t return results until there has been COMMIT TRANSACTION, thus meaning the process won’t continue until the query returns data, so the Invoice details will always be populated.

    Also if there was a ROLLBACK TRANSACTION, the process would time out throwing an error as expected.

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

Sidebar

Related Questions

We use a back-office accounting system with an SQL db2 database. Our sales, service
I have a store (C#) that calls our back office(ASP classic) via a one-pixel
We have a bit of a messy database situation. Our main back-office system is
I have a web-app with a Java back-end that uses Tomcat jdbc-pool for database
I have to pass back information from a different source and can have a
I have a call back url, that i'm am pulling out the Lat and
I'm working on an online forex trading system and a while back we have
Back-end: I have a model (User) that has_many of another model (ContactPreference). Front-end: An
So, let's say that I have a VBA application inside of whatever Office Application.
First some background: VB.NET 2005 Application that accesses a MS-SQL back-end, using multiple Web

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.