USE <DBName>
-- This is the database where the SP and table will reside
GO
CREATE
TABLE
[dbo].[tbl_errlog]
( [Logdate] [datetime]
NULL
,
[ProcessInfo] [
varchar
](100)
[Text] [
](1000)
)
ON
[
PRIMARY
]
create
proc sp_logger
as
begin
declare
@counter
int
select
@counter =
COUNT
(*)
from
dbo.tbl_errlog
if @counter = 0
INSERT
tbl_errlog
EXEC
sp_readerrorlog
end
else
#tmp_errlog
( Logdate datetime,
ProcessInfo
(100),
Text
(1000)
@lastlog datetime
@lastlog=
MAX
(Logdate)
INTO
tbl_errlog (Logdate, ProcessInfo,Text)
SELECT
Logdate, ProcessInfo,Text
FROM
WHERE
Logdate > @lastlog
drop
table
Msg 50000,
Level
16, State 1,
Procedure
TestToSeeWhatTheErrorLineNumberRefersTo, Line 14
Some
Error
go
procedure
TestToSeeWhatTheErrorLineNumberRefersTo
raiserror (
'Some Error'
,16,1)
exec
alter
execute
(
'raiserror ('
',16,1)'
16, State 1, Line 1
@debug
=0
@sql nvarchar(1000)
set
@sql =
'/* some comment or other code
more comments
*/
raiserror ('
if @debug > 0
print @sql
sp_executesql @sql
top
1
rows
sys.partitions
whereobject_id =object_id(@tablename)
sum
row_count
from sys.partitions
where
index_id
in
(0,1)
and object_id =object_id(@
fred (col1
transaction
nocount
on
@i
= 0
while @i < 100000
insert
into
fred
values
(@i)
@i = @i + 1
*
object_id = object_id (
'fred'
#LI
[FileId]
INT
[FileSize]
BIGINT
[StartOffset]
[FSeqNo]
[Status]
[Parity]
[CreateLSN]
DECIMAL
(25, 0)
);
'DBCC LOGINFO('
'msdb'
');'
Msg 213,
16, State 7, Line 1
Column
name
or
number
of
supplied
does
not
match
definition
[RecoveryUnitId]
Andrey, thank you for your contributions on TechNet Wiki. Can you email me? It's edprice at Microsoft. Thanks!
Nice article!