Transient errors during SQL Server failovers
Due to the apparent lack of a universal list, we have gone down the route of retrying on all errors which leave the connection in a broken state.
I think this guys here had a similar problem, might want to check.
Create PROC uspErrorLog ( @userId varchar(15) ,@ExcType varchar(255)='',@ExcMessage varchar(255)='',@ExcSource varchar(255)='',@ExcStackTrace varchar(255)='' ,@pageUrl varchar(150)='' ,@methodName varchar(150)='' ,@lineNo int ,@timeZone varchar(150) )ASBEGIN BEGIN TRY BEGIN TRANSACTIONINSERT INTO [Common].[ErrorLogs] ([userId] ,[ExceptionType] ,[ExceptionMessage] ,[ExceptionSource] ,[ExceptionStackTrace] ,[pageUrl] ,[MethodName] ,[LineNumber] ,[Timezone] ,[LogDate]) VALUES ( @userId ,@ExcType ,@ExcMessage ,@ExcSource ,@ExcStackTrace ,@pageUrl ,@methodName ,@lineNo ,@timeZone ,getdate() ) COMMIT TRAN END TRY BEGIN CATCH IF @@TRANCOUNT > 0 SELECT NULL AS ID ,'Cant Perform Insert Action.Error:' + Error_message() AS Message ,ERROR_LINE() AS linentto ROLLBACK TRAN --RollBack in case of Error END CATCHEND And call this procedure in your stored procedures in {catch} by passing the variables.Like this
BEGIN CATCH
IF @@TRANCOUNT > 0 SELECT NULL AS ID ,'Cant perform operation.Error:' + Error_message() AS Message ,ERROR_LINE() AS linoo ROLLBACK TRAN --RollBack in case of Error DECLARE @methodname VARCHAR(200) ,@msg VARCHAR(max) ,@lineno INT SET @methodname = ( SELECT Error_procedure() ) SET @msg = ( SELECT Error_message() ) SET @lineno = ( SELECT Error_line() ) EXEC [dbo].[uspErrorLog] @CreatedBy ,'' ,@msg ,'' ,'' ,'' ,@methodname ,@lineno ,''
END CATCH