Group: General Forum Members
Last Login: Tuesday, May 12, 2015 6:33 PM
|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):
raiserror('Step 3. Restore Database to Source SQL Server via lite speed',1,1) with nowait
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF (@@ERROR > 50000 OR @ReturnCode > 50000) GOTO QuitWithRollback
PRINT 'NO ERRORS in script'
--IF (@@ERROR = 62309) GOTO QuitWithRollback
@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'
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 datetime
@From = 'email@example.com',
@To = 'firstname.lastname@example.org',
@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
Msg 62309, Level 19, State 1, Line 1
SQL Server has returned a failure message to LiteSpeed 2005 which has
prevented the operation from succeeding.
The following message is not a LiteSpeed 2005 message. Please refer to
SQL Server books online or Microsoft technical support for a