仅在 SQL 服务器上记录错误查询 [英] Logging erroneous queries only on SQL server
问题描述
我有一个看起来很容易实现的目标,但我还没有找到一个好的解决方案.谷歌没有说明,我只是希望我一直在错误的地方寻找解决方案,或者只是试图以错误的方式使用工具......
I have what would seem to be an easy goal to accomplish, yet I have not found a good solution. Google does not shed a light on it and I just hope that I have been looking for a solution in wrong places or just tried to use tools in a wrong way...
或者也许我今天想清楚已经太晚了:)但是我希望你可以在这里帮助我.
Or perhaps it is already too late for me today to think clearly :) But this is where you can help me out, I hope.
我需要能够仅记录在 SQL Server 的特定实例上执行的错误查询.我认为 SQL Profiler 可以让我立即完成,但我无法找到允许我只记录那些返回错误(很可能是解析错误)+ 错误详细信息的查询的设置组合.
I need to be able to log erroneous queries only which were executed on a specific instance of SQL Server. I thought that SQL Profiler would allow me to do it in no time, but I have not been able to find a combination of settings that would allow me to log only those queries, that returned an error (most likely parsing error) + error details.
想象一下,SQL Server 每秒执行 100 条查询,每天只有 1 或 2 个不正确的查询导致解析错误.我只需要能够每天查看 1-2 个查询,而不必为系统上的所有查询运行非常昂贵的配置文件,也不必每天深入研究.
Imagine SQL Server with 100s of queries being executed each second, and only 1 or 2 improperly formed queries each day resulting with a parsing error. I just need to be able to come and see those 1-2 queries per day without having to run a very expensive profile for all queries on the system and having to dig through it each day.
这可能吗?
推荐答案
为 异常事件类、SQL:BatchCompleted 事件类a> 和 RPC:Completed Event Class.为不等于 0 的 Error
添加过滤器.开始跟踪.完成.
Set up a trace for the Exception Event Class, SQL:BatchCompleted Event Class and RPC:Completed Event Class. Add a filter for Error
not equal to 0. Start the trace. Done.
这篇关于仅在 SQL 服务器上记录错误查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!