![](/img/trans.png)
[英]Why does this simple SQL query from SQL Server 2000 have different results in SQL Server 2008?
[英]How to view the last ran sql query from SqlClient data provider on Sql server 2000?
尽管我可以看到最后一次运行的查询是执行的存储过程,但是我没有获得调用SP的参数值。 相反,我得到了以下内容:
StoredProcedureName;1
从以下命令:
DBCC INPUTBUFFER(SPID)
在ObjectExplorer-> Management-> ActivityMonitor中查看SPID的位置
有什么办法可以获取包括执行SP的参数在内的完整文本?
我知道这个答案可能不是您想要的,因为它并不能真正回答您的问题,我跳了一个思路,最终认为这可能会有所帮助。
我不知道您有多少查询,程序有多大...但是出于调试目的,我想对所有查询(纯文本和存储过程)执行类似的操作。 因此,我编写了一个简单的包装器类,该类使我可以执行带参数和不带参数的纯文本查询/存储的proc。 然后,如果发生执行,则将其捕获,使用原始异常以及已执行的查询和所有参数构建一个新的自定义异常,并在自定义消息中全部返回。 我在包装器中使用Oracle,但几乎完全相同:
Public Function ExecuteCommandQuery(ByRef oCMD As OracleClient.OracleCommand) As DataTable
oCMD.Connection = _oConn
Dim dt As New DataTable
'exception if one occured'
Dim DBException As Exception = Nothing
Try
'get an adapter'
Dim cmd As New OracleDataAdapter(oCMD)
'Fill the data table and ket a count of records returned'
cmd.Fill(dt)
Catch ex As Exception
'capture exception, and rethrow after properly closing the Oracle Connection'
DBException = ex
Finally
_oConn.Close()
End Try
'if exception occured, rethrow'
If DBException IsNot Nothing Then
Throw New Exception( _
String.Format("A database error occured: {0} " + _
Environment.NewLine + Environment.NewLine + " --- " + _
Environment.NewLine + Environment.NewLine + _
" Your query: {1}" + _
Environment.NewLine + Environment.NewLine + " --- " + _
Environment.NewLine + Environment.NewLine + _
" Your Parameters: " + Environment.NewLine + "{2}" _
, DBException.ToString(), oCMD.CommandText, GenerateParameterErrorInfo(oCMD)))
End If
Return dt
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.