CS程序,程序运行时通过定时器,每15秒可以执行一次,在运行的时候,Server一定会捕捉client的HOST NAME,我想找最近1分钟里面的所有HOST NAME,这个怎么找?

解决方案 »

  1.   


    sp_MSget_current_activity 64,1
    Host列就是
      

  2.   


    貌似不是SQL server的事儿。 到别的板块看看 ?
      

  3.   

    --try
    select hostname,login_time,last_batch,[status]
    from sys.sysprocesses
    where not hostname = ''
      

  4.   

    我有一个表,记录所有使用这个CS程序的客户端,并用定时器(15秒执行一次)将“在线标记”设为在线状态,程序关闭时会自动将“在线标记”设为不在线状态,但有的时候用户没有关闭程序就拔了网线,造成不使用程序但“在线标记”还是在线状态,这样不大好,所以我才有此想法。
    我只需查看最近1分钟里面和Server通信的所有HOSTNAME,将不在这个集合里面的HOSTNAME对应的用户的“在线标记”设为不在线状态。
      

  5.   

    那么麻烦 直接 抓个 trace 就行了
      

  6.   


    是系统的存储过程,在master库里可以找到,这是2000的SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO-- =============================================
    -- sp_MSget_current_activity
    -- =============================================
    alter procedure dbo.sp_MSget_current_activity @id int = 0, @option int = 0, @obj nvarchar(386) = null, @spid int = 0
    asif (@id = 0)
    begin
        raiserror(N'No SPID specified (spid = %d)', 1, 1, @id)
        return(-1)
    endif (@option <= 0 or @option > 5)
    begin
        raiserror(N'Invalid option %d', 1, 1, @option)
        return(-1)
    enddeclare @stmt as nvarchar(4000)-- =============================================
    -- make tables SPID depended
    -- =============================================
    declare @locktab as sysname
    declare @proctab as sysnameset @locktab = N'##lockinfo' + rtrim(convert(nvarchar(5), @id))
    set @proctab = N'##procinfo' + rtrim(convert(nvarchar(5), @id))if (@option = 1)
    begin
        -- process info (overview of all processes by SPID)
        set @stmt = N'select [Process ID], [User], [Database], [Status], [Open Transactions], [Command], [Application], [Wait Time], [Wait Type], [Wait Resource], [CPU], [Physical IO], [Memory Usage], [Login Time], [Last Batch], [Host], [Net Library], [Net Address], [Blocked By], [Blocking], [Execution Context ID] from ' + @proctab + ' order by [Process ID],[Execution Context ID]'
    end
    else if (@option = 2)
    begin
        -- distinct spid list (old)
        -- set @stmt = N'select [Process ID], [Blocking], [Blocked By] from ' @proctab + ' order by [Process ID]'    -- distinct spid list, only spids with locks
        set @stmt = N'select distinct L.[Process ID], P.[Blocking], P.[Blocked By] from ' + @locktab + ' L, ' + @proctab + ' P where L.[Process ID] = P.[Process ID] order by L.[Process ID]'
    end
    else if (@option = 3)
    begin
        -- distinct object list
        set @stmt = N'select distinct [Object] from ' + @locktab + ' order by [Object]'
    end
    else if (@option = 4)
    begin
        -- locks per spid
        if (@spid = 0)
        begin
            raiserror(N'Error @spid parameter not specified (option %d)', 1, 1, @option)
            return(-1)
        end
        set @stmt = N'select [Object], [Lock Type], [Mode], [Status], [Owner], [Index], [Resource] from ' + @locktab + ' where [Process ID] = ' + rtrim(convert(nvarchar(10), @spid)) + ' order by [Object]'
    end
    else if (@option = 5)
    begin
        -- locks per object
        if (@obj is null)
        begin
            raiserror(N'Error @obj parameter not specified (option %d)', 1, 1, @option)
            return(-1)
        end
        -- locked object is db
        if parsename(@obj,3) is null
        begin
            set @stmt = N'select [Process ID], [Lock Type], [Mode], [Status], [Owner], [Index], [Resource] from ' + @locktab + ' where [Object] = ''' + @obj + ''' and [ObjID] = 0'
        end
        -- locked object is table
        else
        begin
            set @stmt = N'select [Process ID], [Lock Type], [Mode], [Status], [Owner], [Index], [Resource] from ' + @locktab + ' where [Object] = ''' + parsename(@obj,3) + '.' + parsename(@obj,2) + '.' + parsename(@obj,1) + ''''
        end
    end
    exec (@stmt)
    return(0)
    -- =============================================
    -- end sp_MSget_current_activity
    -- =============================================GO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO
      

  7.   

    OK,了解。
    sp_MSget_current_activity
    dbo stored procedure
      

  8.   

    回11楼:
    我用你之前给的代码,稍微改动一下,如下:
    select distinct hostname
    from sys.sysprocesses
    where not hostname = ''and datediff(mi,login_time,getdate())<=4
    即可找到最近5分钟里面有和Server通信的HOSTNAME,然后我把不属于这个集合的HOSTNAME对应的用户的“在线状态”设为不在线就可以了。
    问题解决,结贴!