For Loop debugging

  • I have a for-loop that I am doing several tasks in. This is going to seem really simple, but I'm not sure how to do it. I'd like to have the last step in each loop be a simple write to a file that says:

    Building A Complete

    Building B Complete

    With building a and b being supplied from a variable I'm using elsewhere in the loop. I have a Send Mail on success and a Send Mail on Failure. I'd like to attach the file to those emails.

    Doable?

  • Sure. Make sure that the variables you are using are scoped at the package level and then add your tasks to create the file and send the e-mail after the loop container, not within it.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (5/7/2009)


    Sure. Make sure that the variables you are using are scoped at the package level and then add your tasks to create the file and send the e-mail after the loop container, not within it.

    Yeah, the variable is scoped correctly. I do have a success and fail task email that are both outside, don't want 49 emails 🙂

    What I was curious how to create the file and send it. I saw in the email task where I can attach a file, but I'm not sure how to write to the file each time the loop goes.

    Ideally, I'd send a file on fail that would look like

    Building 1

    Building 2

    Building 3

    and be able to send that file to me on fail so I would know that the last building to succeed is #3, and check on why #4 failed. Just can't figure how to write to a file inside the loop. Do I need to create the file, then start writing to it? Also, I know I'll run into the issue of the file being in place and me trying to write over it, so what do I do with it after I email it? I'd like to delete it if the job succeeds. I guess I could delete the file after I email it on fail?

  • Maybe you could write to a single variable within the loop - just keep on appending messages to it as you iterate round - and then use the contents of the variable as the body of your e-mail...

    Saves all the hassle of writing to a file.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (5/7/2009)


    Maybe you could write to a single variable within the loop - just keep on appending messages to it as you iterate round - and then use the contents of the variable as the body of your e-mail...

    Saves all the hassle of writing to a file.

    Ah, a different variable. Makes sense. I'll give it a shot. If I don't have to write to a file, I'd rather not anyway.

    thanks.

    M@

  • that recommendation should work for you unless you get to a point where the variable cannot hold everything you need.

    In that case, you'll need to use a script task, pass the variable to it, then use vb.net code to write to the file.

    Here is a link to a sample of writing to a text file from VB.Net:

    http://www.freevbcode.com/ShowCode.Asp?ID=4492

    Best of luck,

    Steve

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply