游戏,工作,投资,悟禅

工作就是修行

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在SSIS 2008 中,如果需要在程序中,动态设置配置文件,代码例子如下:

 

     public void ExecutePkg()
        {
                        try
            {
                string PackagePath = @"D:\AC\SQL Server\SQL Server Integration Service\TestConnectionCount\TestConnectionCount\Package.dtsx";
                string PackageConfigPath = @"D:\AC\SQL Server\SQL Server Integration Service\TestConnectionCount\TestConnectionCount\package.dtsconfig";

                Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
                Package pkg = app.LoadPackage(PackagePath, null);
                if (pkg.Configurations.Contains("config")) pkg.Configurations.Remove("config");
                //这一步必须设置
                    pkg.EnableConfigurations = true;

                    Configuration cfg = pkg.Configurations.Add();
                    cfg.ConfigurationType = DTSConfigurationType.ConfigFile;
                    cfg.ConfigurationString = PackageConfigPath;
                    cfg.Name = "config";
                    cfg.PackagePath = PackagePath;
                    
                    //app.SaveToXml(PackagePath, pkg, null);

                if (pkg.Execute() != DTSExecResult.Success)
                {
                   // return;
                }
                
            }
            catch (Exception ex)
            {
                //return;
            }
            
        }

 

posted on 2012-05-21 20:29  爱玩游戏的码农  阅读(668)  评论(0编辑  收藏  举报