通过运行的WinForms SSIS包

我需要通过的WinForms运行SSIS包。

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Deployment; using Microsoft.SqlServer.Dts.Runtime; using Microsoft.SqlServer.Dts.Runtime.Wrapper; using System.Net.Mime; public string sPackage = String.Empty; public string sConfig = String.Empty; private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { OpenFileDialog fDialog = new OpenFileDialog(); fDialog.Title = "Open Package"; fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx"; fDialog.InitialDirectory = @"C:\"; sPackage = fDialog.FileName.ToString(); } private void button2_Click(object sender, EventArgs e) { OpenFileDialog fDialog = new OpenFileDialog(); fDialog.Title = "Open Package"; fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx"; fDialog.InitialDirectory = @"C:\"; sConfig = fDialog.FileName.ToString(); } private void button3_Click(object sender, EventArgs e) { Microsoft.SqlServer.Dts.Runtime.Wrapper.Application app = new Microsoft.SqlServer.Dts.Runtime.Wrapper.Application(); Package package = app.LoadPackage(sPackage,false,null); package.ImportConfigurationFile(sConfig); DTSExecResult result = package.Execute(); MessageBox.Show(result.ToString()); }

但是,这是给我的错误在LoadPackage(sPackage,假,空)

无法隐式转换类型'Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSPackage90'到'Microsoft.SqlServer.Dts.Runtime.Wrapper.Package“。 显式转换存在(是否缺少强制转换?)

--------------解决方案-------------

我想通了,button3_click应该这样处理

private void button3_Click(object sender, EventArgs e)
{
MyEventListener eventListener = new MyEventListener();
Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
Microsoft.SqlServer.Dts.Runtime.Package pkg = app.LoadPackage(sPackage, eventListener,false);
Microsoft.SqlServer.Dts.Runtime.DTSExecResult pkgResults = pkg.Execute(null, null, eventListener, null, null);
MessageBox.Show(pkgResults.ToString());
}

class MyEventListener : DefaultEvents
{
public override bool OnError(DtsObject source, int errorCode, string subComponent,
string description, string helpFile, int helpContext, string idofInterfaceWithError)
{
// Add application-specific diagnostics here.
MessageBox.Show("Error in " + "/t" + source + "/t" + subComponent + "/t" + description);
return false;
}
}

分类:的WinForms 时间:2015-03-15 人气:0
本文关键词: 的WinForms,SSIS
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 1.113 (s). 10 q(s)