Today while debugging a SQL-CLR stored procedure written in C# (using VS 2005) I came upon a frustrating issue. It seems I cannot do things like:
- Debug.Print
- Debug.WriteLine
- Debug.Write
- Console.WriteLine
- Console.Write
Scenario #1: Starting Debug with Console.WriteLine statement in code I immediately get this error
The protected resources (only available with full trust) were: All
The demanded resources were: UI
Scenario #2: While running debug I hit debug.print line and get this error
The protected resources (only available with full trust) were: All
The demanded resources were: Synchronization
This sort of makes sense to me as these statements are trying to use library api's that are purely visual and would not work without an attached debugger. (There is no Console or Debug window when running this purely in SQL Server 2005)
Alternatives?
SqlContext.Pipe.Send is another way to communicate out to the output window but I am fairly new to this statement and it seems to send output in bulks.
Honestly I am not sure of another work around at the moment but I hope this information at least helps.
I am all open to ideas and workaround so please send them to me or post them as comments.


4 comments:
You are aware that you can step into SQLCLR code, right? That would probably be better than print statements, no?
You are correct, break points work perfect.
This unfortunately does not negate not being able to print to output so that at a certain breakpoints I can review the various print outputs to debug (as i would normally do).
Its just a good trace of various operations, i dont want to stop and look at each event as a breakpoint especially in large loops or nested calls.
I just ended up writing a class to handle this. it just writes the log to an xml file on the server. I found the debugger quirky.
Thomas,
That is definitely not a bad approach.
I personally found the debugging descent but not having any easy way to write out things to console is a huge disadvantage and your approach works right around it.
Post a Comment