Keep Package Running if Webclient has Timeout

  • Can someone here tell me how I can handle Webclient timeouts? I have a package downloading approximately 300 zipped files and it got hung up on one download. It just stopped running due to a timeout. I'm not sure how the package can proceed when a timeout occurs.

    Regards:
    Mordred
    Keep on Coding in the Free World

  • i think what you want is instead of the web client, say executing a stored procedure that does a bunch of work, you want to have the web page activiate a service broker you would create;

    the web page would get it's answer instantly that the service broekr was triggered, but the long process would be tripped by the broker, and would not worry about the web page timing out.

    the service broker would execute the procedure or other process, and that's what we are after, right?

    if you give a little more detials, i'm sure we could come up with a sample script for creating the broker and triggering the script? job? procedure?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I'm a Service Broker virgin and just did some quick reading about it and will need to study up about it. I'm not really sure about what more details you would require but basically:

    If there is a timeout, (perhaps) queue the missed download and try it again after all the other downloads are complete. My code that I am running looks like:Try

    ' Logging start of download

    Dim fireAgain As Boolean = True

    Dts.Events.FireInformation(0, "Download File", "Start downloading " + Dts.Variables("User::httpConnection").Value.ToString(), String.Empty, 0, fireAgain)

    ' Create a webclient to download a file

    Dim mySSISWebClient As WebClient = New WebClient()

    Dim pt As String

    pt = Dts.Variables("User::fileName").Value.ToString + ".zip"

    ' Download file and use the Flat File Connectionstring (D:\SourceFiles\Products.csv)

    ' to save the file (and replace the existing file)

    mySSISWebClient.DownloadFile(Dts.Variables("User::httpConnection").Value.ToString, "\\EWPG-SERVICE-60\FA-BUSANALYEC\EconomicDBTemp\DownloadedCSVs\" + Dts.Variables("User::fileName").Value.ToString + ".zip")

    Dts.Variables("User::FullPathTitle").Value = Dts.Variables("User::SaveFile").Value.ToString + pt

    Dts.Variables("User::FileNameDel").Value = Dts.Variables("User::fileName").Value.ToString

    ' Logging end of download

    Dts.Events.FireInformation(0, "Download File", "Finished downloading " + Dts.Variables("User::SaveFile").Value.ToString(), String.Empty, 0, fireAgain)

    ' Quit Script Task succesful

    Dts.TaskResult = ScriptResults.Success

    Catch ex As Exception

    ' Logging why download failed

    Dts.Events.FireError(0, "Download File", "Download failed: " + ex.Message, String.Empty, 0)

    ' Quit Script Task unsuccesful

    Dts.TaskResult = ScriptResults.Failure

    End TryPlease let me know what I am missing regarding more information and I will gladly provide it. Thanks a bunch!

    Regards:
    Mordred
    Keep on Coding in the Free World

  • If you want the package to keep going then you cannot fail the Task. I looked up the exceptions that can be thrown by the DownloadFile method and you'll likely get a WebException. I would add a second catch block that traps for WebException. If you can recreate the error then capture the error message. If the message is standard then you can check for it in your new catch block, and then retry the download if it was in fact a timeout.

    Pseudocode:

    Try

    Try

    Call download file method

    Set Task result to Success

    Catch WebException

    If error message indicates timeout

    Call download file method again

    Set Task result to Success

    Else rethrow error

    End Try

    Catch

    Set Task result to Failed

    End Try

    Edit: adjust Try indentation

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Thanks opc.three, I've nested another try catch statement that catches the time out and so far it I haven't had any problems. However, the process is a long one and because of colleague interruptions and meetings I haven't run straight through the process without manually stopping it. When (if) all have downloaded properly I will post about the success (or failure).

    Thanks again!

    Regards:
    Mordred
    Keep on Coding in the Free World

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

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