Follow Us

Soluții pentru problemele tale IT

Home /Servicii baze de date/SQL Server/Monitorizare sql server login
Home /Servicii baze de date /Monitorizare sql server login

Monitorizare sql server login

  • Data 13/07/2023
  • Autor Bogdan Dumitru
  • Categorie Servicii baze de date, SQL Server
  • 5
  • 694
Configurare noua (How To)

Situatie

Mai jos este o procedura ce primeste ca parametru numele unui login de pe un server Microsoft SQL Server si pentru acest login, returneaza informatii despre activitatea lui pe serverul sql.

Solutie

alter PROCEDURE ActivityByLogin_prc
@Login varchar(max)

as

SELECT
[Session ID] = s.session_id,
[User Process] = CONVERT(CHAR(1), s.is_user_process),
[Login] = s.login_name,
[Database] = ISNULL(db_name(p.dbid), N”),
[Task State] = ISNULL(t.task_state, N”),
[Command] = ISNULL(r.command, N”),
[Application] = ISNULL(s.program_name, N”),
[Wait Time (ms)] = ISNULL(w.wait_duration_ms, 0),
[Wait Type] = ISNULL(w.wait_type, N”),
[Wait Resource] = ISNULL(w.resource_description, N”),
[Blocked By] = ISNULL(CONVERT (varchar, w.blocking_session_id), ”),
[Head Blocker] =
CASE
WHEN r2.session_id IS NOT NULL AND (r.blocking_session_id = 0 OR r.session_id IS NULL) THEN ‘1’
ELSE ”
END,
[Total CPU (ms)] = s.cpu_time,
[Total Physical I/O (MB)] = (s.reads + s.writes) * 8 / 1024,
[Memory Use (KB)] = s.memory_usage * 8192 / 1024,
[Open Transactions] = ISNULL(r.open_transaction_count,0),
[Login Time] = s.login_time,
[Last Request Start Time] = s.last_request_start_time,
[Host Name] = ISNULL(s.host_name, N”),
[Net Address] = ISNULL(c.client_net_address, N”),
[Execution Context ID] = ISNULL(t.exec_context_id, 0),
[Request ID] = ISNULL(r.request_id, 0),
[Workload Group] = ISNULL(g.name, N”)
FROM sys.dm_exec_sessions s LEFT OUTER JOIN sys.dm_exec_connections c ON (s.session_id = c.session_id)
LEFT OUTER JOIN sys.dm_exec_requests r ON (s.session_id = r.session_id)
LEFT OUTER JOIN sys.dm_os_tasks t ON (r.session_id = t.session_id AND r.request_id = t.request_id)
LEFT OUTER JOIN
(

SELECT *, ROW_NUMBER() OVER (PARTITION BY waiting_task_address ORDER BY wait_duration_ms DESC) AS row_num
FROM sys.dm_os_waiting_tasks
) w ON (t.task_address = w.waiting_task_address) AND w.row_num = 1
LEFT OUTER JOIN sys.dm_exec_requests r2 ON (s.session_id = r2.blocking_session_id)
LEFT OUTER JOIN sys.dm_resource_governor_workload_groups g ON (g.group_id = s.group_id)–TAKE THIS dmv OUT TO WORK IN 2005
LEFT OUTER JOIN sys.sysprocesses p ON (s.session_id = p.spid)
where s.login_name = @Login
ORDER BY s.session_id;

Tip solutie

Permanent
Etichetare: activity by sql server login

Voteaza

Up Down
(19 din 33 persoane apreciaza acest articol)
Share
Tweet
Share

Despre Autor

Bogdan Dumitru

Solutii Asemanatoare

  • Listare restaurari efectuate pe un server MSSQL 6
  • Listare backup-uri efectuate pe un server MSSQL 2
  • Listare date despre utilizarea bazei TempDB pe un server MSSQL 0
  • Gasire blocaje pe un server MSSQL Server 3
  • Listare joburi ce nu s-au executat cu succes pe un server MSSQL 2
  • Cele mai utilizate baze de pe un server MSSQL 5

Leave A Comment? × Cancel Reply

30790

Soluții Disponibile

0 Articole

In ultima saptamana

Cele mai recente soluții

  • How to resolve a Windows Update Install Error – 0x80070002
    • 52
    • 3 days ago
  • Bring your Windows Desktop to life with Wallpaper Engine
    • 39
    • 4 days ago
  • How to move Taskbar to top or side on Windows 11
    • 62
    • 17/12/2025
  • Reparare eroare:”Trust Relationship Failed” fără scoatere din domeniu și fără restart (PowerShell)
    • 46
    • 5 days ago
  • You’ve been deleting files the wrong way in Windows
    • 43
    • 6 days ago
© Askit.ro, 2014 - 2025. All rights reserved. Done by Class IT
Share
Tweet
Share