Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trigger runs async - how to fix it?

Author  Topic 

asmguru62
Starting Member

1 Post

Posted - 2011-01-25 : 11:51:56
Hi,

I have a trigger which uses a Stored Proc. That SP has OUTPUT parameter, which is needed further in trigger's code:

EXECUTE spname @ID output
IF (@ID IS NOT NULL) BEGIN
... this code never entered ...
END

Now, here is what I see: if I use any SQL which alters data in a table which has that trigger defined (INSERT,DELETE,UPDATE) and I use this SQL from SQL Server Management Studio - all works perfectly, my history table get rows as per trigger's code (inside that IF() statement).

However, when I use the exact same UPDATE statement FROM the product I am working on - it gives the impression that trigger's code just STARTS that SP and runs further WITHOUT WAITING for SP to return the @ID variable. This makes the value NULL and IF() body of code never entered. It is like EXECUTE runs on one thread and trigger itself on other thread.

Is there any connection properties which may make such difference?
How to fix it?
   

- Advertisement -