Hi,
The below query will hold good only to know the active users connected to the database ( running state). However if the spid is in sleeping state..that is not captured by the below query.
select count(*) from sys.dm_exec_requests where db_name(database_id) = 'MyDatabaseName'
Though the spid is not active, it holds the connection and the resources like memory will be still occupied by that connection.
So I would prefer querying sys.sysprocesses
select * from sys.sysprocesses where dbid= 'databaseid'
As per your requirement you can choose anyone..
Regards,
Rajini