title: WATIN on SSIS script component - Single-Threaded Apartment
body: <p>Hi I need to download a file from a site with forms authentication and further processing the text file with Integration Services.</p>
  
  <p>For the file download I choose to use WATIN, So I imported the Watin library and scripted the browser steps. However when I try to run the code I get an Exception with this Message.</p>
  
  <blockquote>
    <p>The CurrentThread needs to have it's
    ApartmentState set to
    ApartmentState.STA to be able to
    automate Internet Explorer.</p>
  </blockquote>
  
  <p>all this using the 
  (with the  method attribute)</p>
  
  <p>If I try to use this line of code to set it to STA</p>
  
  <pre><code>System.Threading.Thread.CurrentThread.SetApartmentState(Threading.ApartmentState.STA)
  </code></pre>
  
  <p>I get this exception</p>
  
  <blockquote>
    <p>Error:
    System.Reflection.TargetInvocationException:
    Exception has been thrown by the
    target of an invocation. --->
    System.InvalidOperationException:
    Failed to set the specified COM
    apartment state.    at
    System.Threading.Thread.SetApartmentState(ApartmentState
    state)</p>
  </blockquote>
  
  <p>How do I change the SSIS script task to use this Single-Threaded apartment?</p>