You are here: Re: Sql Server incorrectly functioning « MsSQL Server « IT news, forums, messages
Re: Sql Server incorrectly functioning

Posted by MGFoster on 05/25/05 23:20

Steve wrote:
> I have a .NET application with a sql server database backend. Our
> client has been having problems lately with data being returned from
> the database with wrong data. We have error logging in our stored
> procedures and even this is reporting wrong. In every stored procedure
> we have the following:
>
> IF @@Error <> 0
> BEGIN
> EXEC dbo.HandleError
> @ErrorNum = @@Error,
> @ProcID = @@PROCID
> END
>
> Then, HandleError looks like:
>
> CREATE PROCEDURE dbo.HandleError
> @ErrorNum int,
> @ProcID int
> AS
> /*******************************************************************
> * PROCEDURE: HandleError
> * PURPOSE: Handles logging an error
> * CALLED FM: Other stored procedures
> ********************************************************************/
>
> SET NOCOUNT ON
>
> DECLARE @UserID int
> DECLARE @Host varchar(50)
> DECLARE @Len int
> DECLARE @SPName VARCHAR(100)
> DECLARE @ErrorMsg varchar(500)
> DECLARE @ErrorTrace varchar(4000)
>
> -- Get our host name
> SET @Host = HOST_NAME()
> SET @Len = LEN(@Host) - CHARINDEX(':', @Host)
>
> IF @Len > 0 AND CHARINDEX(':', @Host) > 0
> SET @UserID = RIGHT(@Host, LEN(@Host) - CHARINDEX(':', @Host))
> ELSE
> SET @UserID = NULL
>
> SET @SPName = OBJECT_NAME(@ProcID)
>
> SET @ErrorMsg = 'SQL Error: ' + @SPName
>
> SET @ErrorTrace = 'Error: '
> + CAST(@ErrorNum AS VARCHAR(50))
>
> EXEC dbo.InsertApplicationErrors
> @ErrorMessage = @ErrorMsg,
> @ExceptionMessage = '',
> @ErrorStackTrace = @ErrorTrace,
> @UserID = @UserID,
> @HostID = @Host,
> @Logfile = '';
>
> SET NOCOUNT OFF
>
> GO
>
> InsertApplicationErrors inserts a log into a table we have that we
> monitor. We got an error back in the ErrorStackTrace column with
> 'Error: 0'. That shouldn't happen, as the only time we log error is if
> it is not 0.
>
> Does anyone have any ideas on what might be wrong?
>
> Steve
>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You have to set a variable to hold the @@error value, 'cuz doing this:

IF @@error <> 0

causes the @@error value to reset to zero (0). E.g.:

If @@error <> 0
print @@error

will return 0 for the "print @@error" statement.

So, do it this way:

DECLARE @err INT
SET @err = @@error
IF @err <> 0
print @err

will return the error number for the "print @err" statement.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQpTckYechKqOuFEgEQJWHwCfX7UXm/Z+2G45a29oZHy9fA1Z1i4AnAiB
G+K2wPgJC4EKqYIZsgI4x5rQ
=G9He
-----END PGP SIGNATURE-----

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация