title: Call SSIS Package from c# Console Application For Each Loop
body: <p>I have a Console Application which is invoking SSIS Package.Below is the code which is working Fine.</p>
  
  <pre><code>public static void ExecuteSSIS_Staging()
      {
          DataAccessLayer objDAL = new DataAccessLayer();
          LogManager_SSIS objlogM = new LogManager_SSIS();
          String strDestinationFilePath = System.Configuration.ConfigurationManager.AppSettings.Get("FileDownloaded");
  
          try
          {
              Package pkg;
              Application app;
              DTSExecResult pkgResults;
              MyEventListener eventListener = new MyEventListener();
  
              string staging_pkgLocation = System.Configuration.ConfigurationManager.AppSettings.Get("SSIS_Staging_Filepath").ToString();
  
              app = new Application();
              pkg = app.LoadPackage(staging_pkgLocation, eventListener);
              pkgResults = pkg.Execute(null, null, eventListener, null, null);
  
              if (pkgResults == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)
              {
                  Console.WriteLine("Success");
              }
              else if (pkgResults == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
              {
                  string err = "";
                  foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in pkg.Errors)
                  {
                      string error = local_DtsError.Description.ToString();
                      err = err + error;
                  }
                  throw new Exception("Error Occurred while executing the SSIS Staging package:" + err);
              }
  
          }
  
          catch (Exception ex)
          {
              throw new Exception("SSIS Package Execution Failed:" + ex.Message.ToString());
  
          }
      }   
  </code></pre>
  
  <p>Now I am in a position to Invoke this Package inside Foreach Loop.</p>
  
  <pre><code>   static void Main(string[] args)
      {
          try
          {
             foreach (DateTime FileDate in SortedDates)
              {
        ExecuteSSIS_Staging(FileDate);
      }
       }
       Catch(Exception ex)
       {
       }
  }
  </code></pre>
  
  <p>I am getting Many Issues like </p>
  
  <pre><code>  Could not load file or assembly 'Microsoft.SqlServer.ManagedDTS
  </code></pre>
  
  <p>and few other DLL reference error.</p>
  
  <p>Can anyone suggest me, how can i invoke SSIS Package Inside Foreach loop. The main thing is, In my Local machine it is working obsolutely file. But When i deploy it in server, it is not.</p>