sql-server:我怎么知道谁在我的数据库中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3991927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sql-server: how do i know who is in my database?
提问by l--''''''---------''''''''''''
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?
我有一个访问前端和 sql server 后端。我想知道哪些用户当前正在使用该数据库。这可以使用访问或 sql-server 来完成吗?
回答by Gabriel McAdams
In SQL Server, you can run this stored procedure:
在 SQL Server 中,您可以运行此存储过程:
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
回答by mcabral
For SQL Server you can try
对于 SQL Server,您可以尝试
SELECT *
FROM sys.dm_exec_sessions
which will list all the open sessions
这将列出所有打开的会话
回答by Jamie Treworgy
This depends entirely on how security and access to the SQL Server is implemented in your access database
这完全取决于您的访问数据库中如何实现对 SQL Server 的安全性和访问
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.
如果它为所有用户使用一个单一的 SQL Server 登录到 sql 后端(这是常见的),那么就没有办法知道了。
回答by Tony Toews
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:
1) 您,开发人员,必须对 SQL Server 具有 VIEW SERVER STATE 权限才能查看 SQL Server 实例上的所有正在执行的会话。否则,您将只看到当前会话 最简单的方法是使用您的 sysadmin 凭据打开连接(即使用 sqlcmd 或 Management Studio)并发出以下语句:
GRANT VIEW SERVER STATE TO (your network userid)
将查看服务器状态授予(您的网络用户 ID)
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.
2) 在五或十分钟不活动后,访问似乎与 SQL Server 断开连接。我还没有时间进行详细搜索并弄清楚哪些设置(如果有)可以覆盖它。
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.
3) 使用 SQL Server 工具的开发人员可能会连接到 master 数据库,即使他们正在查看数据数据库中的对象。