Domain-UserName in DMV

  • Trying to assemble a 'KILL User' process which will explicitly kill those processes for User = 'MyDomain\MyUser'. the following T-SQL will identify all tranlocks for all users on a DB.

    How can I limit the list of request_session_id to the domain user name: 'MyDomain\MyUser' ?

    declare @databasename varchar(100)

    set @databasename = 'MyUserDB'

    select request_session_id from sys.dm_tran_locks

    where resource_type='DATABASE'

    AND DB_NAME(resource_database_id) = @databasename

    BT
  • You need to join to sys.dm_exec_sessions like this:

    SELECT

    *

    FROM

    sys.dm_tran_locks AS DTL JOIN

    sys.dm_exec_sessions AS DES

    ON DTL.request_session_id = DES.session_id

    WHERE

    DES.login_name = 'MyDomain\MyUser'

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

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