Eroarea apare in la structurile de try and catch in contextul executiei unei comenzi. Exemplific cu o astfel de comanda si locul unde este reportata o eraoare:
IF UPPER(@optype) = 'DB'BEGIN
UPPER(@optype) = 'DB'BEGIN
BEGIN
SET @execmd = N'BACKUP DATABASE [' + @database + '] TO DISK = ''' + @backupfilename + '''' +
SET @execmd = N'BACKUP DATABASE [' + @database + '] TO DISK = ''' + @backupfilename + '''' +CASE WHEN @backupwith IS NULL THEN '' ELSE (' WITH ' + @backupwith) END
CASE WHEN @backupwith IS NULL THEN '' ELSE (' WITH ' + @backupwith) END
BEGIN TRY -- Incorrect syntax near 'TRY'
EXEC(@execmd)
BEGIN TRY -- Incorrect syntax near 'TRY'
EXEC(@execmd)
EXEC(@execmd)
END TRY -- Incorrect syntax near 'TBEGIN CATCH -- backup failure
END TRY -- Incorrect syntax near 'TBEGIN CATCH -- backup failure
BEGIN CATCH -- backup failureSELECT @err = @@ERROR,@ret = @errSELECT @errormsg = 'Full backup of database ' + @database + ' failed with error : ' + CAST(@err as varchar(10))
SELECT @err = @@ERROR,@ret = @errSELECT @errormsg = 'Full backup of database ' + @database + ' failed with error : ' + CAST(@err as varchar(10))
SELECT @errormsg = 'Full backup of database ' + @database + ' failed with error : ' + CAST(@err as varchar(10))SET @output = SPACE(4) + '*** ' + @errormsg + ' ***'IF @debug = 1 PRINT @outputIF @report = 1BEGIN
SET @output = SPACE(4) + '*** ' + @errormsg + ' ***'IF @debug = 1 PRINT @outputIF @report = 1BEGIN
IF @debug = 1 PRINT @outputIF @report = 1BEGIN
IF @report = 1BEGIN
BEGINEXEC sp_OAMethod @file,'WriteLine',NULL,@outputSET @output = SPACE(4) + 'Refer to SQL Error Log and NT Event Log for further details'EXEC sp_OAMethod @file,'WriteLine',NULL,@outputEXEC sp_OAMethod @file,'WriteLine',NULL,''END
EXEC sp_OAMethod @file,'WriteLine',NULL,@outputSET @output = SPACE(4) + 'Refer to SQL Error Log and NT Event Log for further details'EXEC sp_OAMethod @file,'WriteLine',NULL,@outputEXEC sp_OAMethod @file,'WriteLine',NULL,''END
SET @output = SPACE(4) + 'Refer to SQL Error Log and NT Event Log for further details'EXEC sp_OAMethod @file,'WriteLine',NULL,@outputEXEC sp_OAMethod @file,'WriteLine',NULL,''END
EXEC sp_OAMethod @file,'WriteLine',NULL,@outputEXEC sp_OAMethod @file,'WriteLine',NULL,''END
EXEC sp_OAMethod @file,'WriteLine',NULL,''END
ENDCLOSE dcurDEALLOCATE dcurGOTO CLEANUP
END CATCH --Incorrect syntax near 'CATCH'
CLOSE dcurDEALLOCATE dcurGOTO CLEANUP
END CATCH --Incorrect syntax near 'CATCH'
DEALLOCATE dcurGOTO CLEANUP
END CATCH --Incorrect syntax near 'CATCH'
GOTO CLEANUP
END CATCH --Incorrect syntax near 'CATCH'
END CATCH --Incorrect syntax near 'CATCH'