How to find who is connected to a database, from DMV?

  • I have a query that finds all SPID's connected to a particular database:

    select d.name, p.*

    from sys.databases d join sys.sysprocesses p

    on d.database_id = p.dbid

    where d.name = 'my_db'

    But now we have a new rule that we should not use outdated compatibility views, and one of them is sys.sysprocesses. I checked sys.dm_exec_connections/session/requests but failed to replace my existing code. The first two don't have dbid, the last one, requests, has it, but it selects only currently executing statements.

Viewing post 1 (of 1 total)

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