• It appears that a row trying to be fetched is no longer "valid". Sounds like the logic needs to be something more along these lines for the cursor. This example takes that scenario into account. It will only try to do something for a succesful fetch and just moves on to the next fetch if it is a -2. (The code is not a real working version however but the logic is there.):

    DECLARE objectsCur CURSOR FAST_FORWARD LOCAL

    FOR

    SELECT Column1, Column2 FROM SomeTable

    OPEN objectsCur;

    FETCH NEXT FROM objectsCur INTO @command, @name;

    WHILE (@@FETCH_STATUS <> -1) BEGIN

    IF (@@FETCH_STATUS = 0) BEGIN

    BEGIN TRY

    EXEC (@command);

    END TRY

    BEGIN CATCH

    SET @error = 1;

    --note the error and move on to next ones

    PRINT N'Error: ' + @command

    PRINT N' ' + CAST(ERROR_MESSAGE() AS nvarchar(max));

    PRINT N''

    END CATCH;

    END;

    FETCH NEXT FROM objectsCur INTO @command, @name;

    END;

    SET @curStatus = Cursor_Status('local', 'objectsCur');

    IF (@curStatus >= 0) BEGIN

    CLOSE objectsCur;

    DEALLOCATE objectsCur;

    END;