2012-01-11 24 views
0

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

+0

作为最后的手段,你可以达到什么样的丹尼尔提出以下更动态地使用DTS的API。 – 2012-01-12 00:37:52

+0

刚刚访问任务的属性并更改它们而不是运行它呢?那可能吗? – ssokol91 2012-01-12 01:22:18

+1

当然。 [This](http://learnbycoding.com/2011/07/creating-a-simple-ssis-package-programmatically-using-c/#.Tw42oKVSR9Q)与我最近阅读的教程略有不同,但应服务于相同的目的。 – 2012-01-12 01:26:54

回答

0

我找到了一种方法来访问程序包的任务,并设置属性给它。

var task = (TaskHost)package.Executables["Your Package Name"]; 

task.Properties["Any Property"].SetValue(task, "Property Value"); 

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

2

几年前,我们通过ASP.NET Web Forms应用程序做了这样的事情,基本上通过创建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; 
    } 

而且在你的配置:

<connectionStrings> 
    <add name="SsisConnectionString" 
     connectionString="Data Source=<server>;Initial Catalog=MSDB;User Id=<user>;Password=<pwd>;" 
     providerName="System.Data.SqlClient"/> 
</connectionStrings> 
+0

这是如何让他只运行一个任务? – 2012-01-13 23:01:01

2

我想你可以使用API​​打开你的包,禁止其他所有任务,然后运行全包