SQL Server – Script to Monitor Logins on Databases

Use the below script to monitor what applications are running anc connecting to Databases or you want to investigate who is login in to the server

USE master
GO
BEGIN
SET TRANSACTION ISOLATION LEVEL READ  UNCOMMITTED;

SELECT 
	SERVERPROPERTY('Servername') AS ServerName,
	Name,
	login_time,
	last_batch,
	s.status,
	hostname,
	program_name,
	nt_username,
	loginame,
	spid,
	CURRENT_TIMESTAMP AS CurrentDate
FROM sysdatabases d
LEFT JOIN sysprocesses s ON d.dbid = s.dbid

Results

Leave a comment