Hi
I have ForEach Loop which passes a number of url to download files. I have a script with Webclient to download the files from the url inside the loop.
What I am trying to achieve is to let the script task successful even if the download fails. I want to let the script task always successful and handle the error using a variable'Download status' by setting value True or False . Below is the code I have right now.
I set a breakpoint and learnt that it goes through the catch section. It went to the last statment in catch block
Dts.TaskResult = (int)ScriptResults.Success;
I thought this statement would make the script task not to fail but obviously it is something else I need to do.
(I tried to set maxium error count but I had to set it not at the script task but for the package level. It looks like error count increase as the download fails)
Can anyone help me please? Is there a better solution? What am i missing?
public void Main()
{
try
{
Dts.Connections["Course.xml"].ConnectionString = "";
// Logging start of download
bool fireAgain = true;
Dts.Events.FireInformation(0, "Download File", "Start downloading " + Dts.Variables["CourseURL"].Value.ToString(), string.Empty, 0, ref fireAgain);
// Create a webclient to download a file
WebClient mySSISWebClient = new WebClient();
// Set Connection striong
Dts.Connections["Course.xml"].ConnectionString = Dts.Variables["User::eDestinationConnectionString"].Value.ToString();
// Downloal xml
mySSISWebClient.DownloadString(Dts.Variables["CourseURL"].Value.ToString());
// Logging end of download
Dts.Events.FireInformation(0, "Download File", "Finished downloading " + Dts.Connections["Course.xml"].ConnectionString, string.Empty, 0, ref fireAgain);
Dts.Variables["User::DownloadStatus"].Value = true;
// Quit Script Task succesful
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
// Logging why download failed
Dts.Events.FireError(0, "Download File", "Download failed: " + ex.Message, string.Empty, 0);
Dts.Variables["User::DownloadStatus"].Value = false;
// Quit Script Task succesful
Dts.TaskResult = (int)ScriptResults.Success;
}