我正在为用户创建一个Winform来运行SSIS包。以下是我找到的解决方案:
private void button1_Click(object sender, EventArgs e)
{
string sPackage = @"C:\FilePath.dtsx";
string sConfig = @"C:\FilePath.xml";
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open Package";
fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx";
fDialog.InitialDirectory = @"C:\";
sPackage = fDialog.FileName.ToString();
OpenFileDialog f2Dialog = new OpenFileDialog();
fDialog.Title = "Open Package";
fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx";
fDialog.InitialDirectory = @"C:\";
sConfig = fDialog.FileName.ToString();
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;
}
}
以下是我收到此错误的代码行:
Microsoft.SqlServer.Dts.Runtime.Package pkg = app.LoadPackage(sPackage, eventListener, false);
我有.dtxs包的正确文件路径。我有SSIS的经验,只是没有尝试从C#中的Winform执行。我做错了什么?
答案 0 :(得分:0)
在这里找到答案here。由@Faiz回答。
private void button1_Click(object sender, EventArgs e)
{
string pkgLocation;
Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;
MyEventListener eventListener = new MyEventListener();
pkgLocation =
@"C:\FilePath.dtsx";
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgLocation, eventListener);
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;
}
}