在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;
}
}
{
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;
}
}