How to check how many users are connected to a SQL Server

  • How can i retrieve information about the number of connected users to a SQL Server. Is it also possible to check which users are connected to a particular database? 

  • Johan,

    Have a look at running sp_who or sp_who2 in Query Analyzer.  It will show you the databases users are connected to. 

    Each unique SPID is a user connection.

    Cheers,

    Angela

  • You could elaborate on the following ( 3 examples ):

     

    select @@servername as server, count(distinct usr) as users, count(*) as processes from

    ( select sp.loginame as usr, sd.name as db

     from sysprocesses sp join sysdatabases sd on sp.dbid = sd.dbid ) as db_usage

    select usr, count(distinct db) as dbs, count(*) as processes from

    ( select sp.loginame as usr, sd.name as db

     from sysprocesses sp join sysdatabases sd on sp.dbid = sd.dbid ) as db_usage

    group by usr

    order by usr

    select db, usr, count(*) as processes from

    ( select sp.loginame as usr, sd.name as db

     from sysprocesses sp join sysdatabases sd on sp.dbid = sd.dbid ) as db_usage

    where db like('%')

    group by db, usr

    order by db, usr

    /rockmoose


    You must unlearn what You have learnt

  • I also see a script here in SqlserverCentral called sp_who3 ... it is very good .. search for it..


    Alamir Mohamed
    Alamir_mohamed@yahoo.com

Viewing 4 posts - 1 through 3 (of 3 total)

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