如何从 .NET 执行 SSIS 包? [英] How to execute an SSIS package from .NET?

查看:38
本文介绍了如何从 .NET 执行 SSIS 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SSIS 包,最终我也想传递参数,这些参数将来自 .NET 应用程序(VB 或 C#)所以我很好奇是否有人知道如何做到这一点,或者更好的网站提供有关如何操作的有用提示.

I have a SSIS package that eventually I would like to pass parameters too, these parameters will come from a .NET application (VB or C#) so I was curious if anyone knows of how to do this, or better yet a website with helpful hints on how to do it.

所以基本上我想从 .NET 执行一个 SSIS 包,传递它可以在其中使用的 SSIS 包参数.

So basically I want to execute a SSIS package from .NET passing the SSIS package parameters that it can use within it.

例如,SSIS 包将使用平面文件导入 SQL 数据库,但文件的路径和名称可以是从 .Net 应用程序传递的参数.

For instance, the SSIS package will use flat file importing into a SQL db however the Path and name of the file could be the parameter that is passed from the .Net application.

推荐答案

这里是如何从代码中设置包中的变量 -

Here is how to set variables in the package from code -

using Microsoft.SqlServer.Dts.Runtime;

private void Execute_Package()
    {           
        string pkgLocation = @"c:	est.dtsx";

        Package pkg;
        Application app;
        DTSExecResult pkgResults;
        Variables vars;

        app = new Application();
        pkg = app.LoadPackage(pkgLocation, null);

        vars = pkg.Variables;
        vars["A_Variable"].Value = "Some value";               

        pkgResults = pkg.Execute(null, vars, null, null, null);

        if (pkgResults == DTSExecResult.Success)
            Console.WriteLine("Package ran successfully");
        else
            Console.WriteLine("Package failed");
    }

这篇关于如何从 .NET 执行 SSIS 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆