Welcome to Sign in | Help

Re: Backup procedure Msg 170 Incorrect syntax near

  •  10-23-2006, 10:01 AM

    Re: Backup procedure Msg 170 Incorrect syntax near

    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 'T

    BEGIN CATCH -- backup failure

    END TRY -- Incorrect syntax near 'T

    BEGIN CATCH -- backup failure

    BEGIN CATCH -- backup failure

    SELECT @err = @@ERROR,@ret = @err

    SELECT @errormsg = 'Full backup of database ' + @database + ' failed with error : ' + CAST(@err as varchar(10))

    SELECT @err = @@ERROR,@ret = @err

    SELECT @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 @output

    IF @report = 1

    BEGIN

    SET @output = SPACE(4) + '*** ' + @errormsg + ' ***'

    IF @debug = 1 PRINT @output

    IF @report = 1

    BEGIN

    IF @debug = 1 PRINT @output

    IF @report = 1

    BEGIN

    IF @report = 1

    BEGIN

    BEGIN

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    SET @output = SPACE(4) + 'Refer to SQL Error Log and NT Event Log for further details'

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    SET @output = SPACE(4) + 'Refer to SQL Error Log and NT Event Log for further details'

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    EXEC 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,@output

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    END

    CLOSE dcur

    DEALLOCATE dcur

    GOTO CLEANUP

     

    END CATCH --Incorrect syntax near 'CATCH'

    CLOSE dcur

    DEALLOCATE dcur

    GOTO CLEANUP

     

    END CATCH --Incorrect syntax near 'CATCH'

    DEALLOCATE dcur

    GOTO CLEANUP

     

    END CATCH --Incorrect syntax near 'CATCH'

    GOTO CLEANUP

     

    END CATCH --Incorrect syntax near 'CATCH'

    END CATCH --Incorrect syntax near 'CATCH'
View Complete Thread
Powered by Community Server (Commercial Edition), by Telligent Systems