Executing SSIS task from C# application

不想你离开。 提交于 2019-12-23 04:43:40

问题


I can successfully run the SSIS package from my C# App. Is there a way to run a specific task within the SSIS package from .NET (C#) Application?


回答1:


We did something like this with an ASP.NET Web Forms application a few years back basically by creating a SQL Agent Job with just one step that executed the SSIS package that had been deployed to the server and then invoking it via the Enterprise Library

    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;
    }

And in your config:

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



回答2:


I think you can open your package using the API, disable all other tasks and then run the whole package




回答3:


I found a way to access Package's Tasks and set properties to it.

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

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

Thanks for everyone's input anyway.



来源:https://stackoverflow.com/questions/8827987/executing-ssis-task-from-c-sharp-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!