如何通过c#以编程方式运行多个SSIS包
本文关键字:SSIS 运行 方式 何通过 编程 | 更新日期: 2023-09-27 18:10:06
家伙,我使用这个代码片段,我执行多个SSIS包,当第一个完成时,执行另一个需要很长时间,但是我在CMD上运行脚本命令行,它执行得很快。所以我认为这是代码的问题,你知道为什么吗?下面是我的代码:
SSISHelper.ExecuteSSISPackage("/F '"C:''Users''v-nashi''Documents''visual studio 2010''projects''ImportExcel''ImportExcel''LYO_DailyLogin.dtsx'"");
SSISHelper.ExecuteSSISPackage("/F '"C:''Users''v-nashi''Documents''visual studio 2010''projects''ImportExcel''ImportExcel''LYO_COSMOS_Activities.dtsx'"");
/// <summary>
/// Excuete SQL Server Integration Services packages with parameter.
/// </summary>
/// <param name="para">parameter</param>
/// <returns>bool</returns>
public static bool ExecutePackage(string parameter)
{
if (File.Exists(DTExec_Path) == false)
throw new Exception("The file DTExec.exe is not found, or the file is not exist.");
Process process = new Process();
process.StartInfo.FileName = DTExec_Path;
process.StartInfo.Arguments = parameter;
// True if the shell should be used when starting the process; false if the process should be created directly
// from the executable file.
process.StartInfo.UseShellExecute = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
Console.WriteLine("{0} {1}", DTExec_Path, parameter);
process.Start();
process.WaitForExit();
string[] results = process.StandardOutput.ReadToEnd().Split(''n');
foreach (string item in results)
{
if (item.Contains("DTExec: The package execution returned DTSER_SUCCESS (0)."))
return true;
}
return false;
}
我只是想以编程方式运行SSIS包,还是更好的方式?
另一种方法是这样的。
Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
string packagePath = "Path of your SSIS package";
Package package = app.LoadPackage(packagePath, null);
//Assign your variables here.
Variables vars = package.Variables;
vars["FileName"].Value = variables.FileName;
Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();
if (results == DTSExecResult.Success)
{
//Do what u want after success.
}
对于这个U必须使用这个Microsoft.SqlServer.ManagedDTS
库从微软。试着在GAC或其他网站找到它。