Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql-server: how do i know who is in my database?

i have an access front end and sql server backend. i would like to know which users are currently using the database. is this possible to do using access or sql-server?

like image 937
Alex Gordon Avatar asked Oct 21 '10 21:10

Alex Gordon


People also ask

How can I see who is using my database?

You can use the Activity Monitor in SQL Server Management Studio. Once it's open look at the Processes section to see what is running, the login, database being used, and other helpful information. Save this answer.

How many users are connected to my SQL server database?

In SQL Server Management Studio, right click on Server, choose "Activity Monitor" from context menu -or- use keyboard shortcut Ctrl + Alt + A . Good option, but it requires more priviledges than DB_NAME(dbid) extraction from sys.

How do I see what's in a SQL database?

Using SQL Server Management StudioExpand Databases, right-click the database to view, and then click Properties. In the Database Properties dialog box, select a page to view the corresponding information. For example, select the Files page to view data and log file information.


2 Answers

In SQL Server, you can run this stored procedure:

sp_who2

EDIT:

You can use this query if you want to see who is using your server at any given time. This will allow you to further filter at will.

SELECT
    SessionId           = ses.session_id
    ,[Database]    = DB_Name(er.database_id)
    ,[Login]            = ses.login_name
    ,Host               = ses.host_name
    ,StartTime          = er.start_time
    ,ClientAddress      = con.client_net_address
    ,SQLStatement       = st.text
FROM sys.dm_exec_requests er
OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) st
LEFT JOIN sys.dm_exec_sessions ses ON ses.session_id = er.session_id
LEFT JOIN sys.dm_exec_connections con ON con.session_id = ses.session_id
WHERE ses.is_user_process = 0x1
AND ses.session_id != @@SPID
ORDER BY
    ses.session_id
like image 155
Gabriel McAdams Avatar answered Sep 28 '22 08:09

Gabriel McAdams


For SQL Server you can try

SELECT * 
FROM sys.dm_exec_sessions

which will list all the open sessions

like image 30
mcabral Avatar answered Sep 28 '22 08:09

mcabral