I, Rohit Garg, am working as Consultant in IT Company. I am having an around 5 years of experience in MSSQL server & other Microsoft technologies. I am working as DBA in Microsoft SQL Server from last 5 years in e-Commerce, Telecom, Finance domain. In this tenure, I got a chance of working as Database administrator, Developer and trainer on SQL server 2000 to SQL Server 2012. I am holding Master’s degree in Computer Science along with certification in SQL Server & .Net. I like to learn new things by hand-on experience on regular basis. This journey is so far is delightful & valuable with the addition of wonderful friends.
SQL server gives an option to log custom errors in windows event log. We have 2 options of achieving this.
Option 1 : Using xp_logevent
BEGIN TRY
SELECT 10/0
END TRY
BEGIN CATCH
PRINT ERROR_Message()
DECLARE @msg VARCHAR(100)
SELECT @msg = ERROR_Message()
–xp_logevent error_number , errormessage, severity (INFORMATIONAL, WARNING, or ERROR)
EXEC xp_logevent 60000, @msg, error
END CATCH
Option 2 : Using RAISERROR…..WITH LOG
BEGIN TRY
SELECT 10/0
END TRY
BEGIN CATCH
PRINT ERROR_Message()
DECLARE @msg VARCHAR(100)
SELECT @msg = ERROR_Message()