转贴 zjcxc(邹建) ( )---跟踪
开始--程序--MS SQLSERVER
--事件探察器(SQL Profiler)
--文件
--新建--跟踪...
--设置要跟踪的服务器的信息(连接服务器)--确定
--设置跟踪的项目...
--然后数据库的调用情况就会显示出来在跟踪项目设置中,如果不熟悉的话,一般用默认设置
筛选项目有几个可以注意一下:1.DatabaseName 同于你要监测的数据库名(不过这个好像不起作用,我的电脑上设置无效)
2.DatabaseID   同于你要检测的数据库的dbid,可以用 select db_id(N'你要监测的库名')得到dbid
3.ObjectName   同于你要监测的对象名,例如表名,视图名等
4.ObjectID     同于你要监测的对象的id,可以用 select object_id(N'你要监测的对象名')得到id
5.Error        同于错误,如果经常出现某个编号的错误,则针对此错误号
6.Seccess      同于0,失败,1,成功,如果是排错,就过滤掉成功的处

解决方案 »

  1.   

    -- 建立存储运行表:
    create table RunProc (procName varchar(50) ,rundate datetime  ) 
    运行select 前 先把运行的程序名和 系统时间插入这个表里.
    这样就可统计 
      

  2.   

    to chludlf:
    什么意思?
    能详细点么?
    建立表后,如何监控??select??
    谢谢!!!
      

  3.   

    不用事件探察器,可以用sql语句建立跟踪,将情况记录到跟踪文件中下面是一个示例,具体使用的存储过程的语法及作用说明参考sql联机帮助
    -- Create a Queue
    declare @rc int
    declare @TraceID int
    declare @maxfilesize bigint
    set @maxfilesize = 5 -- Please replace the text InsertFileNameHere, with an appropriate
    -- filename prefixed by a path, e.g., c:\MyFolder\MyTrace. The .trc extension
    -- will be appended to the filename automatically. If you are writing from
    -- remote server to local drive, please use UNC path and make sure server has
    -- write access to your network shareexec @rc = sp_trace_create @TraceID output, 0, N'c:\test', @maxfilesize, NULL 
    if (@rc != 0) goto error-- Client side File and Table cannot be scripted-- Writing to a table is not supported through the SP's-- Set the events
    declare @on bit
    set @on = 1
    exec sp_trace_setevent @TraceID, 12, 1, @on
    exec sp_trace_setevent @TraceID, 12, 12, @on
    exec sp_trace_setevent @TraceID, 12, 14, @on
    -- Set the Filters
    declare @intfilter int
    declare @bigintfilter bigintexec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Profiler'
    set @intfilter = 100
    exec sp_trace_setfilter @TraceID, 22, 0, 4, @intfilterset @intfilter = 1
    exec sp_trace_setfilter @TraceID, 23, 1, 0, @intfilterexec sp_trace_setfilter @TraceID, 35, 1, 6, N'pubs'
    -- Set the trace status to start
    exec sp_trace_setstatus @TraceID, 1-- display trace id for future references
    select TraceID=@TraceID
    goto finisherror: 
    select ErrorCode=@rcfinish: 
    go
      

  4.   

    to zjcxc(邹建):
    我想监控客户端某个用户对某个表的select
    但目的是想更改客户端select 的结果不知能否实现?
    谢谢!!