开发者

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

开发者 https://www.devze.com 2023-01-21 15:09 出处:网络
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?In SQL Server, yo

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?


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


For SQL Server you can try

SELECT * 
FROM sys.dm_exec_sessions

which will list all the open sessions


This depends entirely on how security and access to the SQL Server is implemented in your access database

If it uses a a single SQL Server login for all users to the sql backend (which is common), then there's no way to know.


1) You, the developer, must have VIEW SERVER STATE permissions on the SQL Server to see all executing sessions on the instance of SQL Server. Otherwise, you will see only your current session The easiest way would be to open a connection (i.e. using sqlcmd or Management Studio) using your sysadmin credentials and issue the following statement:

GRANT VIEW SERVER STATE TO (your network userid)

2) Access appears to disconnect from SQL Server after five or ten minutes of inactivity. I haven't yet had the time to do a detailed search and figure out what setting, if any, can overrride this.

3) Developers who are using SQL Server tools may be connected to the master database even though they are looking at objects in the data database.

0

精彩评论

暂无评论...
验证码 换一张
取 消