什么是 SQLServer 事件探查器中的“审核注销”?

我正在运行一个数据导入(使用 C #/Linq) ,自然我会尽可能地优化我的查询。为此,我使用 SQL Server Profiler 在 DB 上运行跟踪,并使用 SQL 登录名过滤跟踪(这个名称可以唯一地归属于我的数据导入过程)。

奇怪的是,我的大多数 SQL 语句都非常快:)-很少有查询超过1毫秒。但是在我的所有查询之间的间隔是几行,其中 EventClass 是“ AuditLogin”或“ AuditLogout”-并且“ AuditLogout”的持续时间可以长达一分钟!

这是否与我在导入中使用事务有关?如果是这样,有没有办法找到哪些是重要的查询,以便我可以清理这些?

98503 次浏览

If I remember correct, the duration of an Audit Logout is the amount of time the connection was open. E.g. nothing to do with speed of the command - just the amount of time the login was 'logged in'.

Login/Logout events are related to the setting up / tearing down. IIRC the time is the 'was logged in for time' as opposed to a processing duration as with other log events.

In general, one hides these events unless you suspect there's an issue with connection pool management etc.

The raw times for the batches should be sufficient to diagnose the time the actual activity is taking including the impact of any transactions etc.

Also worth noting as in this answer that Audit Login/Logout may just mean the connection is being reused from / returned to the connection pool.

You can use another field from the event to determine if it's a connection pool event or a 'real' login/logout.

The Audit Logout event class indicates that a user has logged out of (logged off) Microsoft SQL Server. Events in this class are fired by new connections or by connections that are reused from a connection pool.

it's the total time the connection was logged in for, including idle time, so it doesn't indicate a performance problem. Also profiling logins/logouts is very unlikely to cause a performance problem. You'd be better off looking for poorly performing queries, possibly long-running queries.

For more info i suggest https://msdn.microsoft.com/en-us/library/ms175827.aspx :)