How can I use a database event

  • Hi

    Apologies if I'm posting in the wrong place - but this seemed the closest.

    What I've done.....

    When a loading process is finished, it updates the final stage status of a record to Completed.

    I've put in a place a trigger which then inserts a row into another database on this status change

    This then fires off 3 triggers to perform certain subsequent activity - in effect 3 procedures.

    The issue I have it that this is all part of the original transaction. (In this case, if the two databases were out of sync, I'm not bothered, I have a recovery mechanism.) My concern, is that whilst the 3 triggered procedures are running on Database B, I could be holding locks on the original database.

    Ideally, if using Ingres. I would write the three procedures to register for a Database event 'File Completed'. The trigger on the Database Insert table would raise the event 'File Completed' with the associated ID, and the original transaction would commit.

    I think a similar thing could be done in Oracle wih Advanced Queueing.

    I thought I might be able to use this solution with SQL Server - but it seems to be only DDL. Does anyone have any elegant solutions?

    Regards

    Mike

  • If you consider the way you'd do it in Ingres "elegant", then why not just do it that way? Write the 3 stored procedures.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I don't think there's a more elegant way. You could use the DTC (distributed transaction coordinator), but it would hold locks until things were committed, and if your link was down, you couldn't commit anything.

    The slightly more elegant way in SQL is to use Service Broker to Q the event and have it picked up by the other database and take action there. that way if there were some comm issue, you could still commit the event in the first database/table and when things were working, it would occur in the second one. That leaves you some loose coupling, but the chance that things are out of sync for some time.

  • I agree with Steve that Service Broker is probably a way to do what you are looking at doing.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply