Thursday, March 29, 2012

Console.WriteLine generates HostProtectionException

Gotcha!

It took a few minutes of staring at my CLR method (it's actually a ServiceBroker service), trying to figure out why I was getting an exception on something that looked pretty innocuous.

It turned out to be the Console.WriteLine(...) statement. In hindsight, not really much of a surprise . However, for debugging purposes, I'd still like to use Console.WriteLine. Is there a HostProtectionAttribute I can apply that will allow it?

Josh

Yes, you are right, Console.WriteLine is not the appropiate output for debugging in SQL Server. What about using any trace source or even to keep it simple the System.Diagnostics namespace ? This one has some method for the output during the debbuging process.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment