I have a refresh script that I would like to trigger an email if an error condition greater that 50,000 is reached. This will help me determine if the script failed from insufficient disk space or exclusive access could not be given. We use litespeed and the current script will return an error on either condition greater than 50000.Here is part of the restore script (more gets executed after, but I'd like to get the error notification to work most importantly on this restore section):---Script--------------------raiserror('Step 3. Restore Database to Source SQL Server via lite speed',1,1) with nowaitDECLARE @ReturnCode INT SELECT @ReturnCode = 0 IF (@@ERROR > 50000 OR @ReturnCode > 50000) GOTO QuitWithRollbackELSE PRINT 'NO ERRORS in script'--IF (@@ERROR = 62309) GOTO QuitWithRollbackexec master.dbo.xp_restore_database @database = 'database123', @filename = '\\server1\backupdatabase123.BAK', @filenumber = 1, @with = 'REPLACE',@with = 'RECOVERY', @with = 'NOUNLOAD', @with = 'STATS = 10', @with = 'MOVE N''EP88SYS_Data'' TO N''E:\MSSQL\Data\database123.MDF''', @with = 'MOVE N''EP88SYS_Log'' TO N''E:\MSSQL\database123_Log.LDF''',@with = 'STATS = 10' QuitWithRollback:declare @dbname varchar(500)declare @dest varchar(1000)declare @path varchar(512)declare @stt varchar (5000)declare @subject_str varchar(1000)declare @from_str varchar(500)declare @now datetimeEXEC master..usp_sendcdomail @From = 'server1@mail.ca', @To = 'admin@mail.ca', @Subject = 'Refresh failed due to Exclusive Access could not be obtained OR There is insufficient free space', @Body = 'Check Refresh logs asRefresh failed due to Exclusive Access could not be obtained OR There is insufficient free space' IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION--When I run the above the QuitWithRollback section always executes regardless of an error or not and need help getting the right things in the right places so that it only 'QuitWithRollback:' executes when the following occur:Step 3. Restore Database to Source SQL Server via lite speed[b]Msg 62309[/b], Level 19, State 1, Line 1SQL Server has returned a failure message to LiteSpeed 2005 which hasprevented the operation from succeeding.The following message is not a LiteSpeed 2005 message. Please refer toSQL Server books online or Microsoft technical support for asolutionAppreciate help
↧