Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to trace T-SQL function calls
    text
    copied!<p>I'm trying to debug a rather complicated formula evaluator written in T-SQL UDFs (don't ask) that <strong>recursively</strong> (but indirectly through an intermediate function) calls itself, blah, blah.</p> <p>And, of course, we have a bug.</p> <p>Now, using PRINT statements (that can then be read from ADO.NET by implementing a handler for the InfoMessage event), I can simulate a trace for stored procedures.</p> <p>Doing the same for UDF results in a compile time message:</p> <pre><code>Invalid use of side-effecting or time-dependent operator in 'PRINT' within a function. </code></pre> <p>I get the message (PRINT does some stuff like resetting <code>@@ROWCOUNT</code> which definitly is a no-no in UDFs, but how can I trace through the calls? I want to have this trace printed out, so I can study it without getting distracted by stepping through the calls in the debugger...</p> <p><strong>EDIT:</strong> I have tried to use the SQL Profiler (this was a first time one for me), but I can't figure out what to trace for: Although I can get the trace to output the queries sent to the database, they are opaque in the sense that I can't drill down to the Expression-UDFs called: I can trace the actual Stored Procedure invoked, but the UDFs called by this procedure are not listed. Am I missing something? I guess not...</p> <p><strong>EDIT #2:</strong> Allthough the (auto-)accepted answer does trace the function calls - very helpful, thanks - it does not help in finding out what parameters were <em>passed</em> to the function. This, of course, is essential in <strong>debugging</strong> recursive functions. I will post if I find any sollution at all...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload