How Can I Determine Who or What is Accessing a Particular Database

  • Here's the script that I run to check for old processes. It works with both SS 2000 and SS 2008. Appreciate the reminder about new system tables. Will check into it when we get rid of 2000.

    SELECT

    spid

    ,substring( convert(varchar,last_batch,111) ,6 ,5 ) + ' '

    + substring( convert(varchar,last_batch,113) ,13 ,8 )

    as LastBatch

    ,left(convert(sysname, rtrim(loginame)),24) as LoginName

    ,left(HostName,24) as HostName

    ,dbid,left(case when dbid = 0 then null

    when dbid <> 0 then db_name(dbid) end,24) as DatabaseName

    ,status

    ,rtrim(program_name) as ProgramName

    from master.dbo.sysprocesses (nolock)

    where HostName <> ''

    order by last_batch

    Steve

  • I like both your suggestions too...

Viewing 2 posts - 16 through 16 (of 16 total)

You must be logged in to reply to this topic. Login to reply