Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i have a trigger and that print a particular line
SQL
create trigger triginsert on dbo.sample
after insert
as
begin
print 'added successfully'
end



how can i get this print statement in my serverside script
Posted

1 solution

In ADO.Net on the connection object there's an event called InfoMessage

You don't get each message as it's written, I think it works using streams which pushes out the text periodically where there's a lot of message or at the end where there's few.

I haven't tested that this works when your original ADO command is causing the trigger execution, but nonetheless, it would be good if you could reply and let us all know.

C#
connection.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e)
{
  txtMessages.Text +="\n" + e.Message;
};


Any messages written to the text output when running SQL for ADO.Net this includes all messages written using the PRINT command in SQL.

The following article covers this in more detail:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=344[^]
 
Share this answer
 
v2
Comments
Stephen Hewison 20-Jun-12 4:10am    
Why only +1 if the answer was accepted?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900