Call SSIS Package from c# Console Application For

2019-06-12 17:56发布

问题:

I have a Console Application which is invoking SSIS Package.Below is the code which is working Fine.

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());

        }
    }   

Now I am in a position to Invoke this Package inside Foreach Loop.

   static void Main(string[] args)
    {
        try
        {
           foreach (DateTime FileDate in SortedDates)
            {
      ExecuteSSIS_Staging(FileDate);
    }
     }
     Catch(Exception ex)
     {
     }
}

I am getting Many Issues like

  Could not load file or assembly 'Microsoft.SqlServer.ManagedDTS

and few other DLL reference error.

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.

回答1:

The actuall issue is i have added

 Microsoft.SQLServer.ManagedDTS.dll version 9.0 

in one machine. When i tried to open it in other machine, some how DLL is refernced to

      Microsoft.SQLServer.ManagedDTS.dll version 10.0 version. 

I changed it again & executed. Now Working Fine.



标签: c#-4.0 ssis