SQL Server内建SQLDiag工具程序的使用
前言:SQLDiag是SQL Server内建的诊断收集共享程序, [SQL Server 2005] 默认位置:C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLDiag.exe 你可以在任何路径下执行SQLDiag因为此路径已被加到path系统变量,执行sqldiag -?或sqldiag /?即可显示参数说
前言:SQLDiag是SQL Server内建的诊断收集共享程序,
[SQL Server 2005]
默认位置:C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLDiag.exe
你可以在任何路径下执行SQLDiag因为此路径已被加到path系统变量,执行sqldiag -?或sqldiag /?即可显示参数说明
SQL 2005的sqldiag搭配参数请使用正斜线"/"
SQLdiag
可以收集下列类型的诊断信息:
Windows 效能记录
Windows 事件记录文件
SQL Server Profiler 追踪
SQL Server 封锁信息
SQL Server 组态信息
一般使用:
例如:
sqldiag /O C:\temp\sqldiag
(/O 指定输出档案的目录)
最下方会出现
2008/07/01 00:34:42.82 SQLDIAG
Collection started. Press Ctrl+C to stop.表示正在收集中
在此时按下Ctrl+C即可停止收集 收集的信息会储存在指定的C:\temp\sqldiag\目录下,其中数个log_xx.trc档是从C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\路径下所复制的
进阶收集: 修改并指定xml檔,来收集Performance Counter的信息
[SQL Server 2000]
默认位置:C:\Program Files\Microsoft SQL Server\MSSQL\Binn\SQLDiag.exe
切换目录到此位置后执行sqldiag -?或sqldiag /?即可显示参数说明
SQL 2000的sqldiag搭配参数执行要使用"-"
例如: sqldiag -E -O c:\temp\sqldiag.log
(-O 指定输出信息到指定的档案里)
若要让SQL 2000可以取得SQL Trace(*.trc)资料,可以利用下面[Sample Code]或KB281671文件范例SQL在master新增一个名为trace_blackbox的Stored Procedure
KB281671 INF: 预存程序来建立一个 SQL Server 2000 的 blackbox 追踪
然后在排定时间执行trace_blackbox 1以启动trace_blackbox,执行期间这个Instance所有联机的SQL Command都会记录到C:\Program Files\Microsoft SQL Server\MSSQL\Data\blackbox开头.trc,在必要的时间执行trace_blackbox 0以关闭trace_blackbox,而这些trc档案都将会被sqldiag所复制并更名到指定的位置
[Caution]
若执行SQLDiag当时trace_blackbox还开着,档案将无法复制所以SQLDiag.trc会是空的
[Samlp Code]
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[trace_blackbox]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[trace_blackbox]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE trace_blackbox @on int = 2 AS
/* If no argument is passed to the @on parameter then get the current blackbox trace status.
If @on is zero then stop and delete the blackbox trace.
If @on is one then create and start the blackbox trace.
*/
declare @traceid int, @blackboxstatus int, @dir nvarchar(80)
set @traceid = 0
set @blackboxstatus = 0
set nocount on
SELECT @traceid = traceid FROM :: fn_trace_getinfo(0)
where property = 1 and value = 8
IF @on = 0 and @traceid > 0
begin
select @blackboxstatus = cast(value as int) FROM :: fn_trace_getinfo(0)
where traceid = @traceid and property = 5
IF @blackboxstatus > 0 exec sp_trace_setstatus @traceid,0 --stop blackbox trace
exec sp_trace_setstatus @traceid,2 --delete blackbox trace definition
end
IF @on = 1
begin
IF @traceid 0 and @blackboxstatus > 0
begin
select @dir = cast(value as nvarchar(80)) FROM :: fn_trace_getinfo(0)
where traceid = @traceid and property = 2
select 'The blackbox trace is running and the trace file is in the following directory.'
select @dir + '.trc'
end
ELSE select 'The blackbox trace is not running.'
set nocount off
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Microsoft SQL Server is a relational database management system launched by Microsoft. It is a comprehensive database platform that uses integrated business intelligence (BI) tools to provide enterprise-level data management. It is easy to use, has good scalability, and has a high degree of integration with related software. High advantages. The SQL Server database engine provides more secure and reliable storage functions for relational data and structured data, allowing users to build and manage highly available and high-performance data applications for business.

SQLServer or MySQL? The latest research reveals the best database selection. In recent years, with the rapid development of the Internet and big data, database selection has become an important issue faced by enterprises and developers. Among many databases, SQL Server and MySQL, as the two most common and widely used relational databases, are highly controversial. So, between SQLServer and MySQL, which one should you choose? The latest research sheds light on this problem for us. First, let

With the popularity of the Internet, website and application development has become the main business of many companies and individuals. PHP and SQLServer database are two very important tools. PHP is a server-side scripting language that can be used to develop dynamic websites; SQL Server is a relational database management system developed by Microsoft and has a wide range of application scenarios. In this article, we will discuss the development of PHP and SQL Server, as well as their advantages, disadvantages and application methods. First, let's

In web development, the combination of PHP and MySQL is very common. However, in some cases, we need to connect to other types of databases, such as SQL Server. In this article, we will cover five different ways to connect to SQL Server using PHP.

Introduction to how to use PDO to connect to a Microsoft SQL Server database: PDO (PHPDataObjects) is a unified interface for accessing databases provided by PHP. It provides many advantages, such as implementing an abstraction layer of the database and making it easy to switch between different database types without modifying a large amount of code. This article will introduce how to use PDO to connect to a Microsoft SQL Server database and provide some related code examples. step

With the continuous development of the Internet, database selection has become increasingly important. Among the many databases, SQLServer and MySQL are two high-profile options. SQLServer is a relational database management system developed by Microsoft, while MySQL is an open source relational database management system. So how to choose the best database solution between SQLServer and MySQL? First, we can compare these two databases in terms of performance. SQLServer is processing

SQL Server vs. MySQL: Which database is more suitable for high availability architecture? In today's data-driven world, high availability is one of the necessities for building reliable and stable systems. As the core component of data storage and management, the database's high availability is crucial to the business operation of the enterprise. Among the many databases, SQLServer and MySQL are common choices. So in terms of high availability architecture, which database is more suitable? This article will compare the two and give some suggestions.

SQLServer and MySQL are currently two very popular relational database management systems (RDBMS). They are both powerful tools for storing and managing large-scale data. However, they have some differences in handling large-scale data. This article will compare SQL Server and MySQL, focusing on their suitability for large-scale data processing. First, let us understand the basic characteristics of SQLServer and MySQL. SQLServer is developed by Microsoft
