使用C#调用SSIS包小试

来源:互联网 发布:卓智网络 保荐 编辑:程序博客网 时间:2024/06/01 08:41

      试验平台: Windows2003 R2 SP2;SQL SERVER 2005 加所有最新补丁;VS 2005 professional Edition;vs2008。

      如下以前的版本:

      [技术文档]如何使用C#调用SSIS包

      下面是示例:
      使用带参数的包,首先引入
      using Microsoft.SqlServer.Dts.Runtime;
      然后在程序中为包变量赋值,具体方法代码:
      private void runetl()
        {
            Console.WriteLine("ETL start...");
            string filepath = installedPath + "//etl//Package.dtsx";
            Microsoft.SqlServer.Dts.Runtime.Application application
                        =  new Microsoft.SqlServer.Dts.Runtime.Application();
            Package package = application.LoadPackage(filepath, null, true);
            package.Variables["dbservername"].Value = dwservername;
            package.Variables["dbname"].Value = dwdbname;
            package.Variables["varFolderName"].Value = thispath;
            DTSExecResult result = package.Execute();
            if (result.Equals(DTSExecResult.Success))
                listBox1.Items.Add("ETL success");
            else
            {
                listBox1.Items.Add("ETL failed");
                return;
            }
        }
        现在的环境下应该是:

        首先应该加入引用

          C:/Program Files/Microsoft SQL Server/90/SDK/Assemblies/Microsoft.SQLServer.DTSRuntimeWrap.dll 版本 9.0.242.0

 

        加入后看到 Microsoft.SQLServer.DTSRuntimeWrap

        using DtsRunTime = Microsoft.SqlServer.Dts.Runtime.Wrapper;

        这个Wrapper是新版本有的,以前版本只要using DtsRunTime = Microsoft.SqlServer.Dts.Runtime。

           现在引入using Microsoft.SqlServer.Dts.Runtime.Wrapper;