November 30, 2008 at 12:44 pm
Well I think I guess the answer but I not sure so I ask.
If my .Net application calls a Stored procedure to do and insert. And there is a trigger on this table doing a job on insert that take two minutes to execute (I exagerate, it's only for the purpose of the question).
What I want to know is, will the .net app will be idle until the trigger is done? My guess is the database will give back the control to the app after the insert is done and will execute the trigger on is side.
Thank you
Martin
November 30, 2008 at 1:05 pm
Triggers are synchronous, not asynchronous, and are part of your applications synchronous batch of SQL requests. So unless you are using asynchronous .net calls, your app will be stalled until the trigger is done.
Any trigger that takes 2 minutes to complete would be considered unaccaptable in any environment that I have ever worked. Even 2 seconds would be too long 99% of the time.
Anything that takes that long should not be done in a trigger.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
November 30, 2008 at 1:21 pm
Thanks for you answer
The 2 minutes execution was just for the purpose of the question, to help to figure the meaning of the question.
I know a trigger shouldn't be that long.
Martin
November 30, 2008 at 1:25 pm
Glad I could help.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
November 30, 2008 at 2:26 pm
In general, triggers should not start jobs, send email, launch applications or anything of the sort. A trigger should be doing small data verifications or changes, nothing more.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 30, 2008 at 4:47 pm
I just want to add to Gail's statment that if you feel that you do need to do these things in a trigger, you should consider using Service Broker to de-synch these activities from the trigger and the originating batch.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
November 30, 2008 at 11:05 pm
I definately agree with rbarryyoung on this. Service Broker conversations are async and will allow you to queue the work and continue processing.
Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
My Blog | Twitter | MVP Profile
Training | Consulting | Become a SQLskills Insider
Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply