How do I see active SQL Server connections?
You can use the sp_who
stored procedure.
Provides information about current users, sessions, and processes in an instance of the Microsoft SQL Server Database Engine. The information can be filtered to return only those processes that are not idle, that belong to a specific user, or that belong to a specific session.
How to determine total number of open/active connections in ms sql server 2005
This shows the number of connections per each DB:
SELECT
DB_NAME(dbid) as DBName,
COUNT(dbid) as NumberOfConnections,
loginame as LoginName
FROM
sys.sysprocesses
WHERE
dbid > 0
GROUP BY
dbid, loginame
And this gives the total:
SELECT
COUNT(dbid) as TotalConnections
FROM
sys.sysprocesses
WHERE
dbid > 0
If you need more detail, run:
sp_who2 'Active'
Note: The SQL Server account used needs the 'sysadmin' role (otherwise it will just show a single row and a count of 1 as the result)
How to get detailed list of connections to database in sql server 2005?
Use the system stored procedure sp_who2
.
How to list opened sql server connections and close the specific one
For Listing:
select *
from sys.dm_exec_sessions
For Killing specific connection by id:
declare @session_id int;
set @session_id= ''
select
@session_id=cast(req.session_id as int) from sys.dm_exec_requests req where req.command='DbccSpaceReclaim'group by req.session_id
begin
declare @sql nvarchar(1000)
select @sql = 'kill ' + cast(@session_id as varchar(50))
exec sp_executesql @sql
end
How to list active connections on PostgreSQL?
Oh, I just found that command on PostgreSQL forum:
SELECT * FROM pg_stat_activity;
How to see opened connections /running queries in SQL Server 2008?
From the DMVs:
sys.dm_exec_connections
sys.dm_exec_sessions
sys.dm_exec_request
sys.dm_exec_sql_text
Additionally:
- from the Activity Monitor
- from SQL Profiler
- from
sp_whoIsActive
Related Topics
Postgres Analogue to Cross Apply in SQL Server
Join Comma Delimited Data Column
How to Delete from Multiple Tables in the Same SQL Statement
Why Is Using '*' to Build a View Bad
Remove Duplicates Using Only a MySQL Query
Concat Field Value to String in SQL Server
Get the Distinct Sum of a Joined Table Column
What Is a Self Join For? (In English)
How to See Active SQL Server Connections
How to Version Your Database Schema
Extract Date (Yyyy/Mm/Dd) from a Timestamp in Postgresql
How Can a Left Outer Join Return More Records Than Exist in the Left Table
How to Have Nhibernate Only Generate the SQL Without Executing It
Find the Number of Columns in a Table
SQL Server Operating System Error 5: "5(Access Is Denied.)"