SQL Server Profiler中的存储过程输出参数

时间:2021-09-24 15:55:17

I've got a stored procedure with an int output parameter. If I run SQL Server Profiler, execute the stored procedure via some .Net code, and capture the RPC:Completed event, the TextData looks like this:

我有一个带有int输出参数的存储过程。如果我运行SQL Server Profiler,通过一些.Net代码执行存储过程,并捕获RPC:Completed事件,TextData如下所示:

declare @p1 int
set @p1=13
exec spStoredProcedure @OutParam=@p1 output
select @p1

Why does it look like it's getting the value of the output parameter before executing the stored procedure?

为什么它在执行存储过程之前看起来像是获取输出参数的值?

2 个解决方案

#1


5  

The RPC:Completed event class indicates that a remote procedure call has been completed. So the output parameter is actually known at that point. See if tracing the RPC:Started shows you what you expect.

RPC:Completed事件类指示已完成远程过程调用。因此,输出参数实际上是已知的。查看是否跟踪RPC:Started会显示您的期望。

#2


4  

This is, no matter how you look at it, a bug. The intent of the SQL Profiler "TextData" is to enable someone to understand and repeat the stored procedure call. In this case, running this T-SQL can give you a completely different result, if the spStoredProcedure procedure has any logic dependent on the input value of the @OutParam parameter, where that value of "13" were somehow meaningful as an input value.

无论你如何看待它,这都是一个错误。 SQL事件探查器“TextData”的目的是使某人能够理解并重复存储过程调用。在这种情况下,如果spStoredProcedure过程具有依赖于@OutParam参数的输入值的任何逻辑,则运行此T-SQL可以给出完全不同的结果,其中该值“13”在某种程度上有意义作为输入值。

It's easy to see how it can be convenient (enables you to see the output values of the proc call, which would otherwise need to do with the "RPC Output Parameter" event), but it is effectively a "lie" as to what T-SQL equivalent was executed.

很容易看出它是如何方便的(让你看到proc调用的输出值,否则需要与“RPC输出参数”事件有关),但它实际上是一个关于什么T的“谎言” -SQL等效执行。

RELATED: I just came across an article from the Microsoft Customer Service and Support team - about another case where conversion of the RPC:Completed event's BinaryData into a displayable TextData value results in an inaccurate reproduction of the original RPC call - this time codepage issues:
http://blogs.msdn.com/b/psssql/archive/2008/01/24/how-it-works-conversion-of-a-varchar-rpc-parameter-to-text-from-a-trace-trc-capture.aspx

相关:我刚刚看到Microsoft客户服务和支持团队发表的一篇文章 - 关于另一种情况,即将RPC:Completed事件的BinaryData转换为可显示的TextData值会导致原始RPC调用的不准确再现 - 这次代码页发布: http://blogs.msdn.com/b/psssql/archive/2008/01/24/how-it-works-conversion-of-a-varchar-rpc-parameter-to-text-from-a-trace- TRC-capture.aspx

UPDATED: By experimenting with this, I found another peculiarity of the behaviour - the profiler will only use this incorrect initial SET if the input value for that parameter, in the RPC call, was Null. If a non-null value was provided (and the parameter, in .Net SqlClient, had direction "InputOutput"), then that initial SET holds the true input value, and not the resulting output value. But if the input was null, then the output value is set instead. This observation supports the notion that this is simply a null-handling bug in the profiler RPC-to-TSQL display conversion.

更新:通过实验,我发现了行为的另一个特点 - 如果RPC调用中该参数的输入值为Null,则探查器将仅使用此不正确的初始SET。如果提供了非空值(并且该参数在.Net SqlClient中具有方向“InputOutput”),则该初始SET保持真实输入值,而不是结果输出值。但是如果输入为null,则设置输出值。这种观察支持这样的概念:这只是分析器RPC-to-TSQL显示转换中的空处理错误。

#1


5  

The RPC:Completed event class indicates that a remote procedure call has been completed. So the output parameter is actually known at that point. See if tracing the RPC:Started shows you what you expect.

RPC:Completed事件类指示已完成远程过程调用。因此,输出参数实际上是已知的。查看是否跟踪RPC:Started会显示您的期望。

#2


4  

This is, no matter how you look at it, a bug. The intent of the SQL Profiler "TextData" is to enable someone to understand and repeat the stored procedure call. In this case, running this T-SQL can give you a completely different result, if the spStoredProcedure procedure has any logic dependent on the input value of the @OutParam parameter, where that value of "13" were somehow meaningful as an input value.

无论你如何看待它,这都是一个错误。 SQL事件探查器“TextData”的目的是使某人能够理解并重复存储过程调用。在这种情况下,如果spStoredProcedure过程具有依赖于@OutParam参数的输入值的任何逻辑,则运行此T-SQL可以给出完全不同的结果,其中该值“13”在某种程度上有意义作为输入值。

It's easy to see how it can be convenient (enables you to see the output values of the proc call, which would otherwise need to do with the "RPC Output Parameter" event), but it is effectively a "lie" as to what T-SQL equivalent was executed.

很容易看出它是如何方便的(让你看到proc调用的输出值,否则需要与“RPC输出参数”事件有关),但它实际上是一个关于什么T的“谎言” -SQL等效执行。

RELATED: I just came across an article from the Microsoft Customer Service and Support team - about another case where conversion of the RPC:Completed event's BinaryData into a displayable TextData value results in an inaccurate reproduction of the original RPC call - this time codepage issues:
http://blogs.msdn.com/b/psssql/archive/2008/01/24/how-it-works-conversion-of-a-varchar-rpc-parameter-to-text-from-a-trace-trc-capture.aspx

相关:我刚刚看到Microsoft客户服务和支持团队发表的一篇文章 - 关于另一种情况,即将RPC:Completed事件的BinaryData转换为可显示的TextData值会导致原始RPC调用的不准确再现 - 这次代码页发布: http://blogs.msdn.com/b/psssql/archive/2008/01/24/how-it-works-conversion-of-a-varchar-rpc-parameter-to-text-from-a-trace- TRC-capture.aspx

UPDATED: By experimenting with this, I found another peculiarity of the behaviour - the profiler will only use this incorrect initial SET if the input value for that parameter, in the RPC call, was Null. If a non-null value was provided (and the parameter, in .Net SqlClient, had direction "InputOutput"), then that initial SET holds the true input value, and not the resulting output value. But if the input was null, then the output value is set instead. This observation supports the notion that this is simply a null-handling bug in the profiler RPC-to-TSQL display conversion.

更新:通过实验,我发现了行为的另一个特点 - 如果RPC调用中该参数的输入值为Null,则探查器将仅使用此不正确的初始SET。如果提供了非空值(并且该参数在.Net SqlClient中具有方向“InputOutput”),则该初始SET保持真实输入值,而不是结果输出值。但是如果输入为null,则设置输出值。这种观察支持这样的概念:这只是分析器RPC-to-TSQL显示转换中的空处理错误。