madi virgo_007
madi virgo_007

Reputation: 21

Where does the Output go when Print 'Something' in a Trigger?

I'm using SQL Server 2008 R2

If I want to show Print statement from trigger to my .aspx page, Is it possible to return any variable value from trigger ?

Is it possible to use string function i.e. String.Contains() and String.Split() on column value ?

Upvotes: 1

Views: 358

Answers (1)

Mitch Satchwell
Mitch Satchwell

Reputation: 4830

It is sent to the client running the query. More specifically, according to MSDN:

"The message is returned as an informational error to applications using the SQLClient namespace or the ActiveX Data Objects (ADO), OLE DB, and Open Database Connectivity (ODBC) application programming interfaces (APIs). SQLSTATE is set to 01000, the native error is set to 0, and the error message string is set to the character string specified in the PRINT statement. The string is returned to the message handler callback function in DB-Library applications."

In the case of PRINT inside a trigger, it will bubble up to the query that caused the trigger to be called.

If you want to display it through ASP.NET you will need to subscribe to the SqlConnection.InfoMessage event.

Example code: http://msdn.microsoft.com/en-us/library/a0hee08w.aspx

Upvotes: 3

Related Questions