By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,880 Members | 1,415 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,880 IT Pros & Developers. It's quick & easy.

PRINT messages inapproriately ending up in SqlException's message property

P: n/a
Occasionally my users will try to perform an action and be presented with an
exception raised directly from SQL Server, in example:

SET @err = 'a user-friendly error condition message'
RAISERROR(@err, 16, 1, 1)

The exception type thrown is a System.Data.SqlClient.SqlException, and its
message property holds the exception text. Works well for the most part.
However, a lot of times the SQL error conditions happen after a trigger is
fired, and I tend to place informational PRINT statements in my triggers so
I know what they are doing and when. So to give a simplified example to
reproduce this condition...

PRINT 'some non-user-friendly information...'
PRINT 'more non-user-friendly information...'
SET @err = 'a user-friendly error condition message'
RAISERROR(@err, 16, 1, 1)

Now the message property in the corresponding
System.Data.SqlClient.SqlException will contain not only the error text, but
(inexplicably) all the PRINT statements before it, even ones made from other
stored procedures and triggers. I don't want users seeing these things as it
confuses them. I can't just chop everything off after the first line because
some multi-line error messages are legitimate to parse and pass to users. Is
there any way I can keep PRINT messages out of the exception text, or will I
have to do something ugly like prefix all PRINT statements with a character
I can parse out later?

Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.