August 22, 2012 at 12:08 pm
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
August 22, 2012 at 12:13 pm
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
August 22, 2012 at 12:24 pm
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
August 24, 2012 at 7:09 pm
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
August 27, 2012 at 10:21 am
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