{"id":146,"date":"2015-11-11T15:56:18","date_gmt":"2015-11-11T15:56:18","guid":{"rendered":"http:\/\/zappysys.com\/blog\/?p=146"},"modified":"2015-12-18T14:25:50","modified_gmt":"2015-12-18T14:25:50","slug":"ssis-code-check-url-exists-using-c-script-404-error","status":"publish","type":"post","link":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/","title":{"rendered":"SSIS Code &#8211; Check URL Exists using C# Script &#8211; 404 Error"},"content":{"rendered":"<p>In this post you will learn how to use <strong>SSIS Script Task<\/strong> (<strong>C# Code<\/strong>) to detect specific URL found or not (<strong>Detect HTTP 404 Error<\/strong>)<\/p>\n<p>If you using <a href=\"\/\/zappysys.com\/products\/ssis-powerpack\/ssis-json-file-source\/\">SSIS JSON Source<\/a> or our <a href=\"\/\/zappysys.com\/products\/ssis-powerpack\/ssis-rest-api-web-service-task\/\">REST API Task <\/a>then if URL\/Document you trying to read not found then server may return 404 (Not Found) Exception. In order to handle this error gracefully you can use following Script to store status in a variable and then you can use conditional Control Flow to Skip data loading from Web Service.<\/p>\n<p>Step1: Drag Script Task from toolbox<br \/>\nStep2: Select Language as <strong>C#<\/strong><br \/>\nStep3: Select Readonly variable (In this case &#8220;User::url&#8221; &#8211; String Type)<br \/>\nStep4: Select ReadWrite variable (In this case &#8220;User::found&#8221; &#8211; Boolean Type)<br \/>\nStep5: Edit code and paste following script in your script task<\/p>\n<div id=\"attachment_147\" style=\"width: 598px\" class=\"wp-caption alignnone\"><a href=\"\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-147\" class=\"size-full wp-image-147\" src=\"\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png\" alt=\"SSIS C# Code - Check URL Exists (Catch 404 Not Found Error) \" width=\"588\" height=\"403\" srcset=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png 588w, https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error-300x206.png 300w\" sizes=\"(max-width: 588px) 100vw, 588px\" \/><\/a><p id=\"caption-attachment-147\" class=\"wp-caption-text\">SSIS C# Code &#8211; Check URL Exists (Catch 404 Not Found Error)<\/p><\/div>\n<h2>C# Code: Check URL Exists (Detect 404 Error)<\/h2>\n<pre class=\"lang:c# decode:true\">\r\n\tpublic void Main()\r\n\t{\r\n\t\t\/\/ TODO: Add your code here\r\n            Dts.Variables[\"found\"].Value = UrlFound(Dts.Variables[\"url\"].Value.ToString());\r\n\t\tDts.TaskResult = (int)ScriptResults.Success;\r\n\t}\r\n\r\n        private bool UrlFound(string url)\r\n        {\r\n            try\r\n            {\r\n                var request = WebRequest.Create(url);\r\n                var response = request.GetResponse();\r\n                return true;\r\n            }\r\n            catch (WebException we)\r\n            {\r\n                HttpWebResponse errorResponse = we.Response as HttpWebResponse;\r\n                if (errorResponse != null)\r\n                    if (errorResponse.StatusCode == HttpStatusCode.NotFound)\r\n                    {\r\n                        return false;\r\n                    }\r\n                    else\r\n                        throw; \/\/we only look for 404 Error\r\n            }\r\n            return false;\r\n        }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this post you will learn how to use SSIS Script Task (C# Code) to detect specific URL found or not (Detect HTTP 404 Error) If you using SSIS JSON Source or our REST API Task then if URL\/Document you trying to read not found then server may return 404 (Not Found) Exception. In order [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":147,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[37,13,3,38],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>SSIS Code - Check URL Exists using C# Script - 404 Error | ZappySys Blog<\/title>\r\n<meta name=\"description\" content=\"In this post you will learn how to Check URL Exists in SSIS Script Task C# Code (Catch 404 Error). This common pattern will allow you to handle data loading without error.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"SSIS Code - Check URL Exists using C# Script - 404 Error | ZappySys Blog\" \/>\r\n<meta property=\"og:description\" content=\"In this post you will learn how to Check URL Exists in SSIS Script Task C# Code (Catch 404 Error). This common pattern will allow you to handle data loading without error.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/\" \/>\r\n<meta property=\"og:site_name\" content=\"ZappySys Blog\" \/>\r\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/ZappySys\/\" \/>\r\n<meta property=\"article:published_time\" content=\"2015-11-11T15:56:18+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2015-12-18T14:25:50+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png\" \/>\r\n\t<meta property=\"og:image:width\" content=\"588\" \/>\r\n\t<meta property=\"og:image:height\" content=\"403\" \/>\r\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\r\n<meta name=\"author\" content=\"ZappySys\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/zappysys\/\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ZappySys\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/\",\"url\":\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/\",\"name\":\"SSIS Code - Check URL Exists using C# Script - 404 Error | ZappySys Blog\",\"isPartOf\":{\"@id\":\"https:\/\/zappysys.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png\",\"datePublished\":\"2015-11-11T15:56:18+00:00\",\"dateModified\":\"2015-12-18T14:25:50+00:00\",\"author\":{\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/2756c237457fbc95d82cb38962f81f82\"},\"description\":\"In this post you will learn how to Check URL Exists in SSIS Script Task C# Code (Catch 404 Error). This common pattern will allow you to handle data loading without error.\",\"breadcrumb\":{\"@id\":\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#primaryimage\",\"url\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png\",\"contentUrl\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png\",\"width\":588,\"height\":403,\"caption\":\"SSIS C# Code - Check URL Exists (Catch 404 Not Found Error)\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/zappysys.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SSIS Code &#8211; Check URL Exists using C# Script &#8211; 404 Error\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/zappysys.com\/blog\/#website\",\"url\":\"https:\/\/zappysys.com\/blog\/\",\"name\":\"ZappySys Blog\",\"description\":\"SSIS \/ ODBC Drivers \/ API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/zappysys.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/2756c237457fbc95d82cb38962f81f82\",\"name\":\"ZappySys\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5c9be148088ba9b8af8e955c5f7c22b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5c9be148088ba9b8af8e955c5f7c22b5?s=96&d=mm&r=g\",\"caption\":\"ZappySys\"},\"sameAs\":[\"http:\/\/www.zappysys.com\/\",\"https:\/\/www.facebook.com\/ZappySys\/\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/zappysys\/\"],\"url\":\"https:\/\/zappysys.com\/blog\/author\/admin\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SSIS Code - Check URL Exists using C# Script - 404 Error | ZappySys Blog","description":"In this post you will learn how to Check URL Exists in SSIS Script Task C# Code (Catch 404 Error). This common pattern will allow you to handle data loading without error.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/","og_locale":"en_US","og_type":"article","og_title":"SSIS Code - Check URL Exists using C# Script - 404 Error | ZappySys Blog","og_description":"In this post you will learn how to Check URL Exists in SSIS Script Task C# Code (Catch 404 Error). This common pattern will allow you to handle data loading without error.","og_url":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/","og_site_name":"ZappySys Blog","article_author":"https:\/\/www.facebook.com\/ZappySys\/","article_published_time":"2015-11-11T15:56:18+00:00","article_modified_time":"2015-12-18T14:25:50+00:00","og_image":[{"width":588,"height":403,"url":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png","type":"image\/png"}],"author":"ZappySys","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/zappysys\/","twitter_misc":{"Written by":"ZappySys","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/","url":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/","name":"SSIS Code - Check URL Exists using C# Script - 404 Error | ZappySys Blog","isPartOf":{"@id":"https:\/\/zappysys.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#primaryimage"},"image":{"@id":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#primaryimage"},"thumbnailUrl":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png","datePublished":"2015-11-11T15:56:18+00:00","dateModified":"2015-12-18T14:25:50+00:00","author":{"@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/2756c237457fbc95d82cb38962f81f82"},"description":"In this post you will learn how to Check URL Exists in SSIS Script Task C# Code (Catch 404 Error). This common pattern will allow you to handle data loading without error.","breadcrumb":{"@id":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#primaryimage","url":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png","contentUrl":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2015\/11\/ssis-check-url-exists-catch-404-error.png","width":588,"height":403,"caption":"SSIS C# Code - Check URL Exists (Catch 404 Not Found Error)"},{"@type":"BreadcrumbList","@id":"https:\/\/zappysys.com\/blog\/ssis-code-check-url-exists-using-c-script-404-error\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zappysys.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SSIS Code &#8211; Check URL Exists using C# Script &#8211; 404 Error"}]},{"@type":"WebSite","@id":"https:\/\/zappysys.com\/blog\/#website","url":"https:\/\/zappysys.com\/blog\/","name":"ZappySys Blog","description":"SSIS \/ ODBC Drivers \/ API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zappysys.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/2756c237457fbc95d82cb38962f81f82","name":"ZappySys","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5c9be148088ba9b8af8e955c5f7c22b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c9be148088ba9b8af8e955c5f7c22b5?s=96&d=mm&r=g","caption":"ZappySys"},"sameAs":["http:\/\/www.zappysys.com\/","https:\/\/www.facebook.com\/ZappySys\/","https:\/\/twitter.com\/https:\/\/twitter.com\/zappysys\/"],"url":"https:\/\/zappysys.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts\/146"}],"collection":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":0,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/media\/147"}],"wp:attachment":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}