November 29, 2006 at 2:53 pm
Hi
I'm trying to integrate my CRM tool with my financial tool, both apps use SQL 2000 as the bank-end. I 've setup a table that stores the t-sql statement I want to run. A trigger on the table is used to run the t-sql statement. Here is the code used by the trigger:
CREATE TRIGGER [Run_SP] ON dbo.TblRunStoredProcedure
FOR INSERT
AS
Declare @RunID as nvarchar(32)
Declare @SP_Statement as nvarchar(4000)
Set @RunID = (SELECT ins.[Id] FROM inserted ins)
Set @SP_Statement = (SELECT cast(ins.[SP_Statement] as nvarchar(4000)) FROM inserted ins)
Commit tran
If @RunID is not Null and @SP_Statement is not null
Begin
SET XACT_ABORT ON
Execute sp_executeSQL @SP_Statement
Update TblRunStoredProcedure
Set Return_Statement = 'Statement Executed!!!'
Where [ID] = @RunID
End
The problem is that this is not working consistantly, and I do not know if the problem lies with the trigger or within the t-sql statement that's being executed. However if I run the t-sql staement via Query Analyzer it works.
I'd appreciate any help I can get.
Thanks.
November 30, 2006 at 12:09 am
Move the COMMIT TRAN to before the SET statements OR modify the two SELECTs in the SET statements to ready uncommitted data with WITH (NOLOCK)...
A better question is, why are you commiting a transaction in a trigger?
--Jeff Moden
Change is inevitable... Change for the better is not.
November 30, 2006 at 6:22 am
I recmend just remove the COMMIT TRAN, As in the current senario there is no need for this............ even though if u have this then it should be at the end of the code.
cheers
cheers
December 1, 2006 at 11:20 am
Thanks for the help,
I realized that the only solution was to remove the trigger, so I'm calling the isql utility from the client app to execute the stored procedure. So far it's working great.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply