通过winform运行SSIS包

发布于 2024-11-16 15:10:25 字数 1873 浏览 0 评论 0原文

我需要通过 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,false,null) 错误

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

I need to run a SSIS package through winforms.

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()); 
        }

But this is giving me error at LoadPackage(sPackage,false,null)

Cannot implicitly convert type 'Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSPackage90' to 'Microsoft.SqlServer.Dts.Runtime.Wrapper.Package'. An explicit conversion exists (are you missing a cast?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杆小烟枪 2024-11-23 15:10:25

我发现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;
            }
        }

I figured out that button3_click should be handled like this

 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;
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文