Storing Error Description in a Table

  • Hi,

    I've executed the sp and it contains more number of internal sp's. If any sp's execution failure due to some reasons, i want to store the error description into some table. Can you please help me to store the error description in some table.

  • What kind of error do you want to store? System error, procedure error or data error?

  • Thanks for replying.A kind of data error, I want to store it in Table. For example, if it throws some mismatch sql statements, or syntax error, it will be stored in the table

  • I am still not very sure what you want to store because you said something about syntax error.

    I had created a error table before to store the errors of some of my procedures.

    CREATE TABLE Err_Table (ErrID INT IDENTITY(1,1) NOT NULL,

    ProcedureName VARCHAR(250) NOT NULL,

    ErrorDesc VARCHAR(250) NOT NULL,

    ErrorLogTime DATETIME NOT NULL)

    In the procedure that you want to capture the error, you just need to insert data into the table.

    For example if the select statement has an error or it returns 0 record when you expect it should return data.

    DECLARE @Error INT, @Rowcount INT

    SELECT .... FROM ....

    SELECT @Error = @@ERROR, @Rowcount = @@ROWCOUNT

    IF @Error <> 0

    INSERT INTO Err_table (ProcedureName, ErrorDesc, ErrorLogTIme) SELECT 'procedure', 'SELECT ...Statement returned error', GETDATE()

    IF @Rowcount = 0

  • Thanks for your reply

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply