Register for your free account! | Forgot your password?

You last visited: Today at 15:42

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[RELEASE] SQL Error Logger

Discussion on [RELEASE] SQL Error Logger within the SRO PServer Guides & Releases forum part of the SRO Private Server category.

Reply
 
Old   #1
 
Syloxx's Avatar
 
elite*gold: 56
Join Date: Oct 2013
Posts: 1,165
Received Thanks: 774
[RELEASE] SQL Error Logger

SQL Error Logger

About:
The purpose of that error logger is to as the name tells log every error caused by an procedure with that logger in mind (probably mainly my releases).

The logger is able to log any system errors and preconfigured user errors () if the is above level 10.



Implementation:
Table:
Code:
USE [SRO_VT_SYSTEM]
GO

/****** Object:  Table [dbo].[_ErrorLogs]    Script Date: 12/11/2018 7:05:03 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[_ErrorLogs](
	[ErrorLogSN] [BIGINT] IDENTITY(1,1) NOT NULL,
	[LoginName] [VARCHAR](128) NOT NULL,
	[HostName] [VARCHAR](128) NOT NULL,
	[ErrorNumber] [INT] NOT NULL,
	[ErrorSeverity] [INT] NULL,
	[ErrorState] [INT] NULL,
	[ErrorProcedure] [VARCHAR](128) NULL,
	[ErrorLine] [INT] NULL,
	[ErrorMessage] [VARCHAR](MAX) NOT NULL,
	[ErrorDate] [DATETIME] NOT NULL,
 CONSTRAINT [PK_ErrorLogs] PRIMARY KEY CLUSTERED 
(
	[ErrorLogSN] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
Procedure:
Code:
USE [SRO_VT_SYSTEM]
GO
/****** Object:  StoredProcedure [dbo].[_AddErrorLog]    Script Date: 12/11/2018 7:05:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/**
version : 1
author : Syloxx
created date : 2018-09-20
description : Logs the error that has occurred.
return value :
0 = There is no error that has occurred.
1 = The transaction is in an uncommittable state, rolling back transaction.
100 = There is a system error that has occurred.
**/

ALTER PROCEDURE [dbo].[_AddErrorLog]
    @intProcedureID INT = NULL
AS
SET NOCOUNT ON;

SET XACT_ABORT ON;

DECLARE @vcErrorMessage   VARCHAR(4000)
      , @intErrorNumber   INT
      , @intErrorSeverity INT
      , @intErrorState    INT
      , @intErrorLine     INT
      , @vcErrorProcedure VARCHAR(128);

/**_# If inside an uncommittable transaction, rollback and return 1.*/
IF XACT_STATE() = -1
BEGIN
    GOTO ErrorHandler;
END;

/**_# If there is no error information to log, return 0.*/
IF ERROR_NUMBER() IS NULL
BEGIN
    GOTO ErrorHandler;
END;

/**_## Get required informations of the occurred error.*/
SET @intErrorNumber = ERROR_NUMBER();
SET @intErrorSeverity = ERROR_SEVERITY();
SET @intErrorState = ERROR_STATE();
SET @intErrorLine = ERROR_LINE();
SET @vcErrorProcedure = ERROR_PROCEDURE();
SET @vcErrorMessage = ERROR_MESSAGE();

/**_## Log the error that has occurred.*/
IF @vcErrorProcedure = OBJECT_NAME(@@PROCID)
    INSERT dbo._ErrorLogs
    (
        LoginName
      , HostName
      , ErrorNumber
      , ErrorSeverity
      , ErrorState
      , ErrorProcedure
      , ErrorLine
      , ErrorMessage
      , ErrorDate
    )
    VALUES (CAST(ORIGINAL_LOGIN() AS VARCHAR(128))
          , CAST(HOST_NAME() AS VARCHAR(128))
          , @intErrorNumber
          , @intErrorSeverity
          , @intErrorState
          , ISNULL(OBJECT_NAME(@intProcedureID), @vcErrorProcedure)
          , @intErrorLine
          , @vcErrorMessage
          , GETDATE());
ELSE IF @@NESTLEVEL <= 2
    INSERT dbo._ErrorLogs
    (
        LoginName
      , HostName
      , ErrorNumber
      , ErrorSeverity
      , ErrorState
      , ErrorProcedure
      , ErrorLine
      , ErrorMessage
      , ErrorDate
    )
    VALUES (CAST(ORIGINAL_LOGIN() AS VARCHAR(128))
          , CAST(HOST_NAME() AS VARCHAR(128))
          , @intErrorNumber
          , @intErrorSeverity
          , @intErrorState
          , @vcErrorProcedure
          , @intErrorLine
          , @vcErrorMessage
          , GETDATE());

/**_# Rethrow the error that has occurred.*/
SET @vcErrorMessage = 'Error %d, Level %d, State %d, Procedure %s, Line %d, Message: ' + @vcErrorMessage;

RAISERROR(
             @vcErrorMessage
           , @intErrorSeverity
           , 1
           , @intErrorNumber
           , @intErrorSeverity
           , @intErrorState
           , @vcErrorProcedure
           , @intErrorLine
         );

RETURN 100;

ErrorHandler:
IF XACT_STATE() <> 0
    ROLLBACK TRANSACTION;

RETURN 0;
How to Use:
Here you can find an .

The most convenient way to use that error logger is by use a .

Code:
BEGIN TRY
    //YOUR CODE HERE
END TRY
BEGIN CATCH
    EXEC dbo._AddErrorLog;
END CATCH;
Procedure Snippet:
Code:
/**
version : VERSION_NUMBER
author : AUTHOR_NAME
created date : DATETIME
description : PROCEDURE_DESCRIPTION
return value :
0 = Procedure was successfully executed.
1 = The transaction is in an uncommittable state, rolling back transaction.
2 = There is an undefined error that has occurred.
**/

CREATE PROCEDURE [dbo].[PROCEDURE_NAME]
    @PROCEDURE_PARAM INT
AS
SET NOCOUNT ON;
SET XACT_ABORT ON;

DECLARE @intReturnValue INT;

/**_# If inside an uncommittable transaction, rollback and return 1.*/
IF XACT_STATE() = -1
BEGIN
    SET @intReturnValue = 1;
    GOTO ErrorHandler;
END;

BEGIN TRY
    --YOUR CODE GOES HERE
END TRY
BEGIN CATCH
    IF @intReturnValue IS NULL
    OR @intReturnValue = 0
    BEGIN
        SET @intReturnValue = 2;
    END;

    EXEC dbo._AddErrorLog;
    GOTO ErrorHandler;
END CATCH;

RETURN 0;

ErrorHandler:
IF XACT_STATE() <> 0
    ROLLBACK TRANSACTION;

RETURN @intReturnValue;
Syloxx is offline  
Thanks
7 Users
Old 12/11/2018, 08:18   #2
 
Isoline*'s Avatar
 
elite*gold: 0
Join Date: May 2006
Posts: 667
Received Thanks: 348
Nice work, would be useful to hook it up to every sp in the db, and from experience that VT db is awful.
Regards, Iso
Isoline* is offline  
Old 12/11/2018, 09:29   #3

 
SubZero**'s Avatar
 
elite*gold: 270
Join Date: Apr 2017
Posts: 1,030
Received Thanks: 520
good work dude useful for me
SubZero** is offline  
Old 12/12/2018, 21:18   #4
 
kotsh's Avatar
 
elite*gold: 0
Join Date: May 2007
Posts: 360
Received Thanks: 27
Thx Dude
kotsh is offline  
Old 12/15/2018, 03:14   #5


 
Hypnos¥'s Avatar
 
elite*gold: 26
Join Date: Mar 2016
Posts: 1,214
Received Thanks: 1,026
Thanks man, i believe this will be helpful for tracing issues regarding the vsro dbs.
Hypnos¥ is offline  
Old 12/15/2018, 11:29   #6
 
#HB's Avatar
 
elite*gold: 100
Join Date: Sep 2017
Posts: 1,110
Received Thanks: 907
Awesome release.
#HB is offline  
Old 12/15/2018, 13:03   #7
 
topaz..'s Avatar
 
elite*gold: 10
Join Date: Nov 2018
Posts: 192
Received Thanks: 57
Awesome work bruh
topaz.. is offline  
Reply


Similar Threads Similar Threads
[Release]Itemproto(SQL->XML & XML->SQL) Konverter
01/09/2018 - Metin2 PServer Guides & Strategies - 25 Replies
Hey, ich release mal ein Programm mit dem ihr SQL's zu XML's und andersrum konvertieren könnt. Falls es Fehler geben sollte einfach Bescheid geben ;) MfG Marv
[SQL-Error]Sql Database For HellmouthSoruce
04/28/2011 - CO2 Private Server - 10 Replies
Hello, i was setting up the Hellmouth source 5300+ everything was going smoothly and because i'm stupid and noob + i never used/liked navicat i got error when trying to execute the sql databse and here's the error http://www.youtube.com/watch?v=op25Gz_X3Wg
[SQL Error] Sql server 2000
01/02/2011 - Dekaron Private Server - 2 Replies
Enterprice Manager, launching today, I got the following message http://img10.imageshack.us/img10/3899/sqlerrors.j pg Anyone of you knows how to fix it OK problem solved. If anyone of you comes across this problem. Just run from the Start Menu-> Programs-> Microsoft SQL Server-> Server Network Utility and disable the Force Protocol Encryption, and Winsock Proxy Click Apply and OK Topic CLOSE
[Help]I cant find SQL 2000+SP4... and janvier`s sql has some error...
10/07/2009 - Dekaron Private Server - 9 Replies
can some1 give me SQL 2000+SP4 dl link plz? :O thanks for helping



All times are GMT +1. The time now is 15:43.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.