向SSIS包传参调用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DtsManage = Microsoft.SqlServer.Dts.Runtime;

namespace TN.SynthEmployee
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = System.Configuration.ConfigurationManager.AppSettings["PackagePath"];
            string tableSource = System.Configuration.ConfigurationManager.AppSettings["Temp_ViewHRInfo"];


            DtsManage.Package package;
            DtsManage.Application dtsApp = new DtsManage.Application();
            package = dtsApp.LoadPackage(path, null);

            try
            {
                Console.WriteLine(DateTime.Now.ToString() + ": Load SSIS Package Success");

                //获取参数类型
                //SSIS包中的参数以package.Variables["key"]形式获取,其中key为参数名
                Type t = package.Variables["TableName"].GetType();
                //参数赋值
                package.Variables["User::TableName"].Value = Convert.ChangeType(tableSource, t);


                DtsManage.DTSExecResult pkgResults = package.Execute();

                if (pkgResults == DtsManage.DTSExecResult.Failure)
                {
                    Console.WriteLine(DateTime.Now.ToString() + ": DTS Package Run Faild");
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToString() + ": DTS Package Run Success");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally {
                package.Dispose();
            }
            Console.ReadLine();
        }
    }
}
posted @ 2011-12-10 18:35  徐某人  阅读(1288)  评论(0编辑  收藏  举报