How to get l last user login details connect the database in SQL server

Anandhswarupp 105 Reputation points
2025-01-22T13:48:49.46+00:00

How to get last user login details connected the database in SQL server

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,477 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 46,041 Reputation points
    2025-01-22T13:52:35.07+00:00

    By default SQL Server logs only failed login in ErrorLog and this only with user name without further details.

    You have to change the logging mode, see

    https://learn.microsoft.com/en-us/sql/ssms/configure-login-auditing-sql-server-management-studio?view=sql-server-ver16

    Or you have to implement an own logging.


  2. Erland Sommarskog 116.9K Reputation points MVP
    2025-01-22T22:05:20.0366667+00:00

    This query gives you the login times for the users currently logged in:

    SELECT login_time, login_name FROM sys.dm_exec_sessions WHERE is_user_process = 1
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.