存储过程或命令使用哪些参数执行?

Mar*_*cke 6 sql-server-2008-r2 nhibernate

我们正在使用nHibernate它从.NET代码生成查询。有时,某些查询会卡在sp_whoisactive列表中,我们无法找出原因。我有一种感觉,它与丢失或损坏的参数有关。sp_whoisactive但是,当我运行时,我只看到参数名称(在示例中:)@p0,而不是实际值。有没有办法在进程仍在运行时检索此信息?

例子:

SELECT 
    this_.Id as Id6_2_, this_.HRNumber as HRNumber6_2_, 
    this_.FirstName as FirstName6_2_, this_.LastName as LastName6_2_, 
    this_.StatusTypeID as StatusTy5_6_2_, 
    this_.PropertyId as PropertyId6_2_, this_.DepartmentGroupId as Departme7_6_2_, 
    property2_.PropertyID as PropertyID10_0_, 
    property2_.PropertyCode as Property2_10_0_, 
    property2_.LMSCode as LMSCode10_0_, property2_.PropertyName as Property4_10_0_, 
    property2_.Report as Report10_0_, department3_.Id as Id4_1_, 
    department3_.Name as Name4_1_, department3_.DisplayName as DisplayN3_4_1_ 
FROM 
    [dbo].[EmployeeDepartmentGroupView] this_ 
LEFT OUTER JOIN
    [dbo].[Property] property2_ ON this_.PropertyId=property2_.PropertyID 
LEFT OUTER JOIN
    [dbo].[DepartmentGroup] department3_ ON this_.DepartmentGroupId=department3_.Id 
WHERE 
    this_.HRNumber LIKE @p0;
Run Code Online (Sandbox Code Playgroud)

请注意,这是从nHibernate.

规格:SQL Server 2008r2

小智 3

如果您怀疑哪些进程/过程等导致了问题,您是否可以不使用 SQL Profiler/Trace/扩展事件来获取数据?- 然后将其完整记录,包括传递的参数。- 当然,这需要提前运行 - 一旦运行就没有任何用处。然而,经过良好过滤的跟踪对性能的影响相对较低,因此您可以让跟踪始终运行。

以下是设置跟踪/探查器的基本方法:如何使用 SQL Server Profiler 创建跟踪

一旦您了解了这些概念,您就可以找到更好的信息来源。