MSSQL Server errorlog
Определение расположения error log
SELECT SERVERPROPERTY('ErrorLogFileName')
Переключение Error Log
EXEC
sp_cycle_errorlog
Чтение Error log
EXEC sys.xp_readerrorlog @p1,@p2,@p3,@p4
- @p1 - Value of error log file you want to read:
- 0 = current,
- 1 = Archive #1,
- 2 = Archive #2,
- etc...
- @p2 - Log file type:
- 1 or NULL = error log,
- 2 = SQL Agent log
- @p3 - Search string 1: String one you want to search for
- @p4 - Search string 2: String two you want to search for to further refine the results
Чтение error log в таблицу
/*
create table #tmp
(
logdate datetime,
processinfo nvarchar(250),
text nvarchar(250),
)
*/
/*alter table #tmp
alter column [text] text*/
drop table #tmp
--insert #tmp exec xp_readerrorlog 6
select * from #tmp
where
processinfo = 'Logon'
and text like 'Login succeeded%for user%sqluser%'
select * from #tmp
where
processinfo = 'Logon'
and text like 'Login succeeded%for user%sqluser%'
and text not like '%CLIENT%local%'