从C#应用程序执行SSIS任务

我可以从我的C#App成功运行SSIS包。 有没有办法在.NET(C#)应用程序中运行SSIS包中的特定任务?

几年前,我们使用ASP.NET Web窗体应用程序做了类似的事情,基本上是通过创建一个SQL代理作业,只执行一步,执行已部署到服务器的SSIS包,然后通过企业库调用它

  public bool ExecutePackage(string jobName) { int result = -1; bool success = false; try { // "SsisConnectionString" will be the name of your DB connection string in your config Database db = DatabaseFactory.CreateDatabase("SsisConnectionString"); using (DbCommand dbCommand = db.GetStoredProcCommand("sp_start_job")) { db.DiscoverParameters(dbCommand); db.SetParameterValue(dbCommand, "job_name", jobName); db.SetParameterValue(dbCommand, "job_id", null); db.SetParameterValue(dbCommand, "server_name", null); db.SetParameterValue(dbCommand, "step_name", null); db.ExecuteNonQuery(dbCommand); result = Convert.ToInt32(db.GetParameterValue(dbCommand, "RETURN_VALUE")); } } catch (Exception exception) { success = false; } switch (result) { case 0: success = true; break; default: success = false; break; } return success; } 

在您的配置中:

    

我认为你可以使用API​​打开你的包,禁用所有其他任务,然后运行整个包

我找到了一种方法来访问Package的任务并为其设置属性。

 var task = (TaskHost)package.Executables["Your Package Name"]; task.Properties["Any Property"].SetValue(task, "Property Value"); 

无论如何,谢谢大家的意见。