Calling web service from Trigger

Last post 05-14-2007 5:50 AM by FrankKalis. 9 replies.
Page 1 of 1 (10 items)
Active Topics My Discussions Unanswered Sort Posts: Previous Next
  • 11-28-2006 7:48 AM

    Calling web service from Trigger

    Hi,

    My application needs to fire a web service and pass a record to it as soon as one particular field is updated on the databse.
    I serched on net and came to know that this is very much posible in SQL 2005 but my production server has SQL 2003.

    Is firing a web servie from trigger possible in SQL 2003???
    I need to cll this web service real time when one field is updated. Is there any othee way??

    Thanks for going through this any help is very much appreciated.

    Thanks,
    Nilay
  • 11-28-2006 8:00 AM In reply to

    Re: Calling web service from Trigger

    Problem with triggers is that they are synchronous - everything else has to wait until the trigger has finished. So you really should avoid contacting the outside world from within a trigger.

    And no, there is no bypass if you let the trigger insert data into another table, which has its own trigger that fires the web service - the first trigger will wait for the second one to finish.

    Not sure there is a SQL 2003 - you are probably running SQL 2000 on Windows 2003.

    The common way in SQL 2000 is to have a log table where your trigger dumps the data that needs further processing. You then have a job that executes at a set time interval, and does the processing - in this case, somehow mixed up with a webservice.

  • 11-28-2006 8:31 AM In reply to

    Re: Calling web service from Trigger

    Thanks for the reply, and you are right its SQL 2000, sorryy for that
    but actually my Trigger is not inserting data into any other table, There is only one trigger involved and one web service.

    I know this situation is quite wierd but this is how the setup is currently where i'v joined in. There is one application which inserts records into the database and at that time the status field for that record is set to "default". Afterwards when record is finally udated the status field changes to "Completed" and at that time i have to fire this web serivce which does some final validations. So at this point i have to call the web service real time and pass the record to it.

    This is the problem that I cannot have a batch running in night and pick up all the records and then call web service, but i have to call it then and there real time...this is the main problem.

    I know i can do it on SQL 2005 but how to accomplih this goal on SQL 2000??
  • 11-28-2006 8:44 AM In reply to

    Re: Calling web service from Trigger

    Adriaan,

    Thanks for reply..

    Sorry I misunderstood earllier.. Yes it is Sql Server 2000 on Windows 2003. They are planning to upgrade to 2005 but dont know when.. and I heard in 2005 it is possible to call web service.. But even in that case since it would still be synchronous then it wouldnt be good option to call directly from trigger.. right..

    I think I will have to go with the way u suggested no matter what..

    Nilay.
  • 11-29-2006 3:12 AM In reply to

    • satya
    • Top 10 Contributor
    • Joined on 11-05-2002
    • United Kingdom
    • Posts 24,050
    • Microsoft MVP
      Moderator

    Re: Calling web service from Trigger

    Yes you can call the webservices with an URL, but not advisable to use a trigger in this case as explained by Adrian above, because when there is a change in webservice then the trigger will have troubles. I think it is a better option to write a C# class that calls the web service and expose it as a COM component. You could then call the COM component from the SQL trigger.


    Satya SKJ
    Microsoft SQL Server MVP
    Contributing Editor & Forums Moderator
    http://www.SQL-Server-Performance.Com
    This posting is provided AS IS with no rights for the sake of knowledge sharing.
    -Satya S K J

    SQL Server MVP

    View Satya Shyam K Jayanty's profile on LinkedIn &
    Knowledge is Power, you will gain by sharing it. SSQA.net - Invisible contributions to the users & visible success in SQL Community.

    SqlServer-QA.net (SSQA.net)<

    ↑ Grab this Headline Animator

  • 11-29-2006 6:44 AM In reply to

    Re: Calling web service from Trigger

    The simple answer is "Never Do That"

    Roji. P. Thomas
    http://toponewithties.blogspot.com
  • 11-29-2006 7:10 PM In reply to

    Re: Calling web service from Trigger

    This is my guess....
    Don't you think you can write a procedure for the update and return the OUTPUT to the application when the column/field updated then you call the webservice within your application without impacting the database.


    Mohammed U.
    MohammedU.
    Microsoft SQL Server MVP
    Moderator
    SQL-Server-Performance.com

    All postings are provided “AS IS” with no warranties for accuracy.
  • 11-29-2006 10:47 PM In reply to

    • jezemine
    • Top 150 Contributor
    • Joined on 09-08-2006
    • Washington USA
    • Posts 127

    Re: Calling web service from Trigger

    this is sooooo wrong. triggers need to be fast. web services can be slow for any number of reasons, for example, the web server that hosts it is down.

    do you really want your db to lock up for 30 sec on each insert while your trigger waits for some web server to timeout? [:)]

    the only thing i can think of that might be worse would be popping a messagebox from a trigger. or perhaps calling Environment.Exit() [:)]


    SqlSpec: a fast and comprehensive data dictionary generator for
    SQL Server 2000/2005, Analysis Server 2005, Access 97/2000/XP/2003
    www.elsasoft.org
  • 05-14-2007 4:07 AM In reply to

    • satya
    • Top 10 Contributor
    • Joined on 11-05-2002
    • United Kingdom
    • Posts 24,050
    • Microsoft MVP
      Moderator

    Re: Calling web service from Trigger

    I believe you haven't read out the thread completely, it is not advisable in this case.
    (I have seen your email too)
    Explain your requirement so that the resolution can be achievable in a better way here.

    Satya SKJ
    Microsoft SQL Server MVP
    Writer, Contributing Editor & Moderator
    http://www.SQL-Server-Performance.Com
    This posting is provided AS IS with no rights for the sake of knowledge sharing.
    Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it.
    -Satya S K J

    SQL Server MVP

    View Satya Shyam K Jayanty's profile on LinkedIn &
    Knowledge is Power, you will gain by sharing it. SSQA.net - Invisible contributions to the users & visible success in SQL Community.

    SqlServer-QA.net (SSQA.net)<

    ↑ Grab this Headline Animator

  • 05-14-2007 5:50 AM In reply to

    Re: Calling web service from Trigger

    Even better to start a new thread than hijacking someone else's one. [:)]

    --
    Frank Kalis
    Moderator
    Microsoft SQL Server MVP
    Webmaster:http://www.insidesql.de
    --
    Frank Kalis
    Microsoft SQL Server MVP
    Contributing Editor, Writer & Forum Moderator http://www.sql-server-performance.com
    Webmaster: http://www.insidesql.org
    My blog: http://www.insidesql.org/blogs/frankkalis/
    View Frank Kalis's profile on LinkedIn
Page 1 of 1 (10 items)
Active Topics   My Discussions    Unanswered Posts


.© 2010 Jude O'Kelly All Rights Reserved.