Reputation: 11
In SSIS [VS 2012], is there a way to check to see if a URL is valid before continuing with the loading process? If possible I would like to separate a list of URLs between valid and invalid, and only load the valid URLs. I already have a package created loading a list of URLs, but I'm receiving errors in the history from the invalid URLs and I would like to clean up those errors by filtering out the invalid URLs. Examples would be greatly appreciated! Thanks!
Upvotes: 0
Views: 1569
Reputation: 11
I was able to achieve the above by using the script task component along with the following C# piece of code. I passed my URL through a variable and was able to see if it was valid or invalid. I then set up my precedence constraints based on that. Thanks!
public void Main()
Dts.Variables["Found"].Value = UrlFound(Dts.Variables["URL1"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
private bool UrlFound(string url)
{
try
{
//Creating the HttpWebRequest
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//Setting the Request method HEAD, you can also use GET too.
request.Method = "HEAD";
//Getting the Web Response.
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//Returns TRUE if the Status code == 200
response.Close();
return (response.StatusCode == HttpStatusCode.OK);
}
catch
{
return false;
}
}
Upvotes: 1