|
I'm working on the following stored procedure but may need a little help.. Any help is appreciated. My stored procedure is executed from a trigger and receives a parameter (QuoteID) In my stored procedure
FOR EACH PART do the following
(comments are locked)
|
|
This scenario is screaming out for a solution that involves Service Broker and not a trigger. You could see a whole lot of trouble putting logic that spans databases in a trigger. Essentially the session that causes the trigger to fire will be waiting while the code in the trigger executes. The transaction will be open and causing locks and blocks while the code you show executes. If this execution gets held up for any reason then other transactions like your first one will be blocked. Your whole system could come to a standstill very quickly and very frequently. Service Broker allows for two disconnected systems to play their part in a process without affecting the execution of the other in any detrimental way. Triggers are a good way to apply business logic/rules/conditions to data but should be used carefully as they also have the ability to cause a system a lot of pain. I know this isnt going to be an answer you were hoping for but if you are early enough in the design of this system that you can build it with Service Broker then you will be building a system that will be robust and will scale a lot better as the system(s) grow. I totally agree with that. Great advice. But if you cannot use Service Broker, then schedule a job that will regularly check the criteria and send mails accordingly.
Aug 09 '12 at 10:02 AM
Usman Butt
Yeah, a manual version of the SB architecture where it is acceptable to have the process run on a cycle like that is also a good solution.
Aug 09 '12 at 10:05 AM
Fatherjack ♦♦
I have just read about 10 articles on service broker. It seams like this is structured for database to database communication. I'm just trying to retrieve data from tables, calculate and evaluate the results, then send an email. Does anyone have an example of this through service broker?
Aug 09 '12 at 07:00 PM
technette
Can you give us any idea about the acceptable duration between the first transaction taking place and the email being sent please? The main "red-flag" in your question is the embedding of this logic inside a trigger. This exposes the transaction to a much greater risk of locking/blocking. If you can accept a little delay then you can have your first transaction just write a row into a logging table. This will be as little delay in your trigger as possible and let the primary transaction continue unhindered. Then a SQL Agent job can cycle (every minute/5 minutes/10 minutes - it depends on your requirements) through this table and carry out the second step of your logic. This disconnects the cross database work from the primary system work and means they will be less likely to interfere with each other.
Aug 09 '12 at 07:13 PM
Fatherjack ♦♦
For sure, if you are Ok to run it nightly then use the trigger to make a table of work to be actioned over night then use a SQL Agent job to apply as much logic or as many steps as you want/need to take.
Aug 09 '12 at 07:52 PM
Fatherjack ♦♦
(comments are locked)
|

