技术开发 频道

C#编程方式执行包的任务


【IT168技术文档】

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; //由于此命名空间有些成员跟其它命名空间有些冲突,因此替换一下 using dts=Microsoft.SqlServer.Dts.Runtime; namespace WinSSIS { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog().Equals(DialogResult.OK)) { this.textBox1.Text = this.openFileDialog1.FileName; Executepackage(this.openFileDialog1.FileName); } } private void Executepackage(string path) { string message=null ; //创建一个DTS执行用应程序 dts.Application app = new Microsoft.SqlServer.Dts.Runtime.Application(); //新建一个包 dts.Package package = new Microsoft.SqlServer.Dts.Runtime.Package(); //加载一个包 package= app.LoadPackage(path,null); //给包变量赋值 if(package.Variables.Contains("filePath")) { package.Variables["filePath"].Value = @"d:\SSIS包路径测试.txt"; } //执行包 dts.DTSExecResult result= package.Execute(); //获取包的执行信息 if(result.Equals(dts.DTSExecResult.Failure)) { for (int i = 0; i < package.Errors.Count;i++ ) { message += package.Errors[i].Description; } } if (result.Equals(dts.DTSExecResult.Success)) { message = "包执行成功成!"; } else { message = "其它1"; } MessageBox.Show(message); } } }
0
相关文章