Home All Groups Group Topic Archive Search About

PRINT command in trigger

Author
22 Jul 2006 7:17 AM
Curious Trigger
Hi there,

where can I see the output of a PRINT command which runs inside a trigger?

May I configure SQL Server 2005 to write those PRINT-outputs to the eventlog
or to a file?

I know that PRINT outputs are shown on the 'message' tab in query analyzer,
if a sql-batch is invoked interactively.

But I am a little lost, where those output goes while triggers are running.

Any help will be greatly appreciated!

Sincerly,
a curious trigger

Author
22 Jul 2006 7:51 AM
Tim Stahlhut
I suggest looking at xp_logevent to see if that works for what you want.

Tim S

Show quote
"Curious Trigger" <Curious_Trigger@nospam.gmx.net> wrote in message
news:%23DaZU6VrGHA.5008@TK2MSFTNGP05.phx.gbl...
> Hi there,
>
> where can I see the output of a PRINT command which runs inside a trigger?
>
> May I configure SQL Server 2005 to write those PRINT-outputs to the
> eventlog or to a file?
>
> I know that PRINT outputs are shown on the 'message' tab in query
> analyzer, if a sql-batch is invoked interactively.
>
> But I am a little lost, where those output goes while triggers are
> running.
>
> Any help will be greatly appreciated!
>
> Sincerly,
> a curious trigger
>
Author
22 Jul 2006 7:28 PM
Curious Trigger
Hi Tim,
thank's a lot for this tip. I tried it and I can see the informational
message in the eventlog of the sql server and in the server's log.

Curious Trigger

Show quote
"Tim Stahlhut" <staht***@netzero.com> schrieb im Newsbeitrag
news:12c3m7h35s2q0eb@corp.supernews.com...
>I suggest looking at xp_logevent to see if that works for what you want.
>
> Tim S
>
> "Curious Trigger" <Curious_Trigger@nospam.gmx.net> wrote in message
> news:%23DaZU6VrGHA.5008@TK2MSFTNGP05.phx.gbl...
>> Hi there,
>>
>> where can I see the output of a PRINT command which runs inside a
>> trigger?
>>
>> May I configure SQL Server 2005 to write those PRINT-outputs to the
>> eventlog or to a file?
>>
>> I know that PRINT outputs are shown on the 'message' tab in query
>> analyzer, if a sql-batch is invoked interactively.
>>
>> But I am a little lost, where those output goes while triggers are
>> running.
>>
>> Any help will be greatly appreciated!
>>
>> Sincerly,
>> a curious trigger
>>
>
>
Author
22 Jul 2006 9:24 AM
Erland Sommarskog
Curious Trigger (Curious_Trigger@nospam.gmx.net) writes:
> where can I see the output of a PRINT command which runs inside a trigger?
>
> May I configure SQL Server 2005 to write those PRINT-outputs to the
> eventlog or to a file?
>
> I know that PRINT outputs are shown on the 'message' tab in query
> analyzer, if a sql-batch is invoked interactively.
>
> But I am a little lost, where those output goes while triggers are
> running.

PRINT statements in an SQL batch, be that a trigger or elsewhere,
reaches the client just like an error messages. Then what happens in
the client depends on how errors and messages are handled in the
application.

Normally, you should not have any PRINT or SELECT statements in a trigger,
but I assume that this is for debug purposes.


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
22 Jul 2006 7:32 PM
Curious Trigger
Hello Erland,
thank you very much for your respond!

I saw a print statements in the stored procedure uspPrintError of the
AdventureWorks-sample database. It is called from uspLogError in case there
is an error condition during the processing of uspLogError.

In my opinion this is a valid usage of the PRINT statement: if anything else
fails there are chances that the message gets through to the client.

Curious Trigger

Show quote
"Erland Sommarskog" <esq***@sommarskog.se> schrieb im Newsbeitrag
news:Xns980873F211C6CYazorman@127.0.0.1...
> Curious Trigger (Curious_Trigger@nospam.gmx.net) writes:
>> where can I see the output of a PRINT command which runs inside a
>> trigger?
>>
>> May I configure SQL Server 2005 to write those PRINT-outputs to the
>> eventlog or to a file?
>>
>> I know that PRINT outputs are shown on the 'message' tab in query
>> analyzer, if a sql-batch is invoked interactively.
>>
>> But I am a little lost, where those output goes while triggers are
>> running.
>
> PRINT statements in an SQL batch, be that a trigger or elsewhere,
> reaches the client just like an error messages. Then what happens in
> the client depends on how errors and messages are handled in the
> application.
>
> Normally, you should not have any PRINT or SELECT statements in a trigger,
> but I assume that this is for debug purposes.
>
>
> --
> Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se
>
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button