Wednesday, February 15, 2012

ERR_SYSERR(104):PRM:SQLExecDirect failed (trigger)

The trigger fire correctly with insert new comment, but when user update a
comment field, I got the following error: ERR_SYSERR(104):PRM:SQLExecDirect
failed
I create a trigger as following:
DECLARE @.commentsOut AS VARCHAR(2000), @.acct AS BigInt, @.sub AS smallInt
IF UPDATE(comment1) OR UPDATE(comment2) OR UPDATE(comment3) OR
UPDATE(comment4)
--Get Acct, Sub number
SELECT @.acct = memb.acct, @.sub = prof.no
FROM memb
JOIN prof ON memb.rowno = prof.rowno
--Get Comments
EXEC usp_LMA_CUBE_trig_comments @.acct, @.sub, @.comments = @.commentsOUT OUTPUT
--Update or insert into other server with linkserver
EXEC usp_LMA_CUBE_upd_comments @.acct, @.sub, @.commentsOUT
Please help,
CulamI run an update statement in Query Analyzer, it works fine, but not in the
application.
"culam" wrote:

> The trigger fire correctly with insert new comment, but when user update a
> comment field, I got the following error: ERR_SYSERR(104):PRM:SQLExecDire
ct
> failed
> I create a trigger as following:
> DECLARE @.commentsOut AS VARCHAR(2000), @.acct AS BigInt, @.sub AS smallInt
> IF UPDATE(comment1) OR UPDATE(comment2) OR UPDATE(comment3) OR
> UPDATE(comment4)
> --Get Acct, Sub number
> SELECT @.acct = memb.acct, @.sub = prof.no
> FROM memb
> JOIN prof ON memb.rowno = prof.rowno
> --Get Comments
> EXEC usp_LMA_CUBE_trig_comments @.acct, @.sub, @.comments = @.commentsOUT OUTP
UT
> --Update or insert into other server with linkserver
> EXEC usp_LMA_CUBE_upd_comments @.acct, @.sub, @.commentsOUT
> Please help,
> Culam|||On Mon, 28 Mar 2005 16:21:03 -0800, culam wrote:

>The trigger fire correctly with insert new comment, but when user update a
>comment field, I got the following error: ERR_SYSERR(104):PRM:SQLExecDirec
t
>failed
>I create a trigger as following:
>DECLARE @.commentsOut AS VARCHAR(2000), @.acct AS BigInt, @.sub AS smallInt
>IF UPDATE(comment1) OR UPDATE(comment2) OR UPDATE(comment3) OR
>UPDATE(comment4)
>--Get Acct, Sub number
>SELECT @.acct = memb.acct, @.sub = prof.no
>FROM memb
>JOIN prof ON memb.rowno = prof.rowno
>--Get Comments
>EXEC usp_LMA_CUBE_trig_comments @.acct, @.sub, @.comments = @.commentsOUT OUTPU
T
> --Update or insert into other server with linkserver
>EXEC usp_LMA_CUBE_upd_comments @.acct, @.sub, @.commentsOUT
Hi Culam,
First, I'd like to point out two errors in your trigger code that are
probably not the cause of the error message you report (at least not
directly), but that are important nonetheless.
First: triggers should refer to the inserted and/or deleted pseudotables
to find out which rows were affected by the operation that fired the
trigger. If you refer to the base tables only, you're working on the
entire set of rows in the table, whether updated or not.
Second: triggers fire once per executed statement, not once per row
affected. Your code should ensure that it will also work properly if the
inserted and/or deleted pseudotables contain no rows or more than one
row. If you just use SELECT @.xxx = yyy FROM inserted to copy the new
data in a variable, SQL Server will pick (randomly) one of the new rows,
ignoring all others. It won't even raise an error or warning condition!!
Another (potential - I don't really know your requirements) flaw in your
code is the lack of BEGIN and END after the IF. Are you aware that you
need BEGIN and END if you want more than one statement to be executed
conditionally? Your current code is equivalent to
IF UPDATE(..) OR UPDATE(..) ...
BEGIN
-- Get Acct, Sub number
SELECT @.acct = ..., @.sub = ...
FROM ...
END
-- Get Comments
EXEC usp_LMA_CUBE_trig_comments ...
-- update or insert ...
EXEC usp_LMA_CUBE_upd_comments ...
If an update is executed but none of the columns comment1 through
comment4 is in the SET list, then the stored procedures will be executed
with @.acct and @.sub equal to NULL.
Now we get to your actual error message. I've never seen this message
before; in fact, I've never seen an error message on SQL Server that
uses this format. I suspect that your client software has done some
reformatting of the error message. Could you check the error message you
get when you run the same update statement from Query Analyzer?
I'm quite sure that the error is not raised in the code you posted. That
leaves the two stored procedures as possible offenders. But since you
didn't post the code of these procedures, I can't say any more than
that. Maybe the error will spontaneoously disappear once you fix the
other issues I've mentioned. If not, then I suggest you code the updated
trigger code plus the code of both stored procedures. Posting the DDL
(as CREATE TABLE statements) for all tables involved, plus some rows of
sample data (as INSERT statements) might help as well.
Oh, and by the way - have you considered normalizing your data, storing
the comments in a seperate table where they probably belong? Names like
comment1, comment2, comment3, comment4 r of a repeating group...
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

No comments:

Post a Comment