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

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

问题描述

我有一个SSIS包,最终我想传递参数太多,这些参数将来自一个.net应用程序(VB或者C#),所以我很好奇,如果任何人知道如何做到这一点,或更好,但一个网站关于如何做到这一点有用的提示。所以基本上我想从.net传递它可以在它使用SSIS包参数执行SSIS包。例如,SSIS包将使用平面文件导入到SQL数据库但该文件的路径和名称可能是从.NET应用程序传递的参数。 谢谢!

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. So basically I want to execute a SSIS package from .NET passing the SSIS package parameters that it can use within it. 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. THANKS!

推荐答案

下面是如何在包从code设置变量 -

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

using Microsoft.SqlServer.Dts.Runtime;

private void Execute_Package()
    {           
        string pkgLocation = @"c:\test.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");
    }

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

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