跟踪和重播事件Tracing and Replaying Events

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics

在 SMO 中,命名空间中的 跟踪重播 对象 Microsoft.SqlServer.Management.Trace 提供对 SQL Server ProfilerSQL Server Profiler 功能(用于监视或的实例)的编程访问 SQL ServerSQL Server Analysis ServicesAnalysis ServicesIn SMO, the Trace and Replay objects in the Microsoft.SqlServer.Management.Trace namespace provide programmatic access to the SQL Server ProfilerSQL Server Profiler functionality, which is used for monitoring an instance of SQL ServerSQL Server or Analysis ServicesAnalysis Services. 您可以捕获有关每个事件的数据并将其保存到文件或表中供以后分析。You can capture and save data about each event to a file or table to analyze later. 例如,可以监视生产环境,了解哪些过程由于执行速度太慢影响了性能。For example, you can monitor a production environment to see which procedures are impeding performance by executing too slowly.

跟踪重播 对象提供一组对象,这些对象可用于在实例上创建跟踪 SQL ServerSQL ServerThe Trace and Replay objects provide a set of objects that can be used to create traces on an instance of SQL ServerSQL Server. 可以在您自己的应用程序中使用这些对象为 SQL ServerSQL ServerAnalysis ServicesAnalysis Services 手动创建跟踪。These objects can be used from within your own applications to create traces manually for SQL ServerSQL Server or Analysis ServicesAnalysis Services. 此外,SMO Trace 对象可用于读取通过监视 SQL ServerSQL ServerAnalysis ServicesAnalysis Services 或 DTS 日志记录创建的 SQL 跟踪文件和表。Additionally, SMO Trace objects can be used to read SQL Trace files and tables that were created by monitoring SQL ServerSQL Server, Analysis ServicesAnalysis Services, or DTS logging.

SMO 跟踪 对象允许您执行以下功能:SMO Trace objects let you perform the following functions:

  • 创建跟踪。Create a trace.

  • 设置跟踪筛选器。Set filters on the trace.

  • 设置正在跟踪的事件。Set the events that are being traced.

  • 停止或启动跟踪。Stop or start a trace.

  • 读取跟踪文件和跟踪表。Read trace files, and trace tables.

  • 获取有关跟踪中的事件的信息。Get information about events on a trace.

  • 获取有关跟踪中的筛选器的信息。Get information about filters on a trace.

  • 以编程方式操作跟踪数据。Manipulate trace data programmatically.

  • 写入跟踪表和跟踪文件。Write trace tables and trace files.

  • 重播跟踪文件或跟踪表。Replay trace files or trace tables.

应用程序可以使用来自 跟踪重播 对象的跟踪数据,也可以使用 SQL Server Profiler手动检查这些数据。The trace data from the Trace and Replay objects can be used by the SMO application, or it can be examined manually by using SQL Server Profiler. 跟踪数据还与同时提供跟踪功能的 SQL 跟踪 存储过程兼容。The trace data is also compatible with the SQL Trace stored procedures that also provide tracing capabilities.

SMO 跟踪对象驻留在 Microsoft.SqlServer.Management.Trace 命名空间中,该命名空间要求引用 Microsoft.SQLServer.ConnectionInfo.dll 文件。The SMO trace objects reside in the Microsoft.SqlServer.Management.Trace namespace, which requires a reference to the Microsoft.SQLServer.ConnectionInfo.dll file.

跟踪重播 对象需要一个 microsoft.sqlserver.management.common.serverconnection> Server 对象,以便与实例建立连接 SQL ServerSQL ServerThe Trace and Replay objects require a ServerConnectionServer object to establish a connection with the instance of SQL ServerSQL Server. Microsoft.sqlserver.management.common.serverconnection>对象位于命名空间中,该命名空间需要对 Microsoft.SQLServer.ConnectionInfo.dll 文件的引用。The ServerConnection object resides in the Microsoft.SqlServer.Management.Common namespace, which requires a reference to the Microsoft.SQLServer.ConnectionInfo.dll file.

备注

64位平台上不支持 跟踪重播 对象。The Trace and Replay objects are not supported on a 64-bit platform.