August 2, 2012 at 10:00 am
I know i can audit the time when a user logged in and also for failed logins. My goal is log when a user logins and log's out of sql server. Is that possible? Any thoughts?
August 3, 2012 at 6:26 am
i too want to know this...
Regards
Durai Nagarajan
August 3, 2012 at 6:29 am
Profiler or a trace for the audit logout event.
Or build a custom script which checks sys.dm_exec_sessions for a spid and username and run it every so oftern, when it appears you can log it as the login, when its gone then its logged out.
August 3, 2012 at 9:15 am
anthony.green (8/3/2012)
Profiler or a trace for the audit logout event.Or build a custom script which checks sys.dm_exec_sessions for a spid and username and run it every so oftern, when it appears you can log it as the login, when its gone then its logged out.
Thanks. Do you have such script handy?
August 3, 2012 at 9:29 am
I do.
this script adds a stored procedure, which i assume you would put in master:
linky for sp_AddMyLogonTrace.txt
After running the script to create the procedure, if you run
EXEC sp_AddMyLogonTrace
it will either create (or stop & drop ) the Login trace,and also creates a view for the trace to make it easier to review:
a simple SELECT * FROM sp_LogonTrace
makes it fast to look at what I'm after.
Lowell
August 3, 2012 at 9:33 am
the advantage of the procedure is if i decide i want one running all the time, i can set the procedure to execute on server startup, so the trace gets restarted every time the server bounces.
Lowell
August 3, 2012 at 10:18 am
Lowell (8/3/2012)
the advantage of the procedure is if i decide i want one running all the time, i can set the procedure to execute on server startup, so the trace gets restarted every time the server bounces.
Thanks. I am little reluctant to have trace running all the time, i was thinking to use this dmv sys.dm_exec_sessions to get the same info. thoughts?
August 3, 2012 at 10:32 am
Id say that a server side trace has an incedibly small footprint because its not capturing much; plus you get better tracing than watxhing a dmv and infering a logoff.
Test both methods yourself so you can be sure. I personally have 3 traces running on my servers. A logon trace, a dml and a ddl, but i admit h the server only has 100 or so simultaneous usersmax.
Lowell
August 6, 2012 at 12:01 pm
Lowell (8/3/2012)
Id say that a server side trace has an incedibly small footprint because its not capturing much; plus you get better tracing than watxhing a dmv and infering a logoff.Test both methods yourself so you can be sure. I personally have 3 traces running on my servers. A logon trace, a dml and a ddl, but i admit h the server only has 100 or so simultaneous usersmax.
first time i ran the sproc, it dropped the trace and view. Second when i executed i got this error message
'Msg 214, Level 16, State 3, Procedure sp_trace_setfilter, Line 1
Procedure expects parameter '@value' of type 'int'.
'
August 6, 2012 at 12:24 pm
my fault; in 2008 this line raises an error:
I updated the script to correct the issue.
exec sp_trace_setfilter @traceidout,12,0,4, 50 -- AND SPID >= N'50'
changed to:
exec sp_trace_setfilter @traceidout,12,0,4, 50 -- AND SPID >= 50
Lowell
August 6, 2012 at 12:40 pm
Lowell (8/6/2012)
my fault; in 2008 this line raises an error:I updated the script to correct the issue.
exec sp_trace_setfilter @traceidout,12,0,4, 50 -- AND SPID >= N'50'
changed to:
exec sp_trace_setfilter @traceidout,12,0,4, 50 -- AND SPID >= 50
Thanks for prompt response. I just posted another question on forum, but even you might know. Why do i see an entry to audit logout right after i login ? and then i see another entry when i actually logout.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply