zoukankan      html  css  js  c++  java
  • 在C#.Net 中调用SSIS 开发的Package,并用日志记录Package执行中的错误和异常信息

    using System;
    using System.Collections.Generic;
    using System.Text;
    using DTSRuntime = Microsoft.SqlServer.Dts.Runtime;
    using Microsoft.SqlServer.Server;
    using System.Data;
    using System.Xml;
    using System.Xml.XPath;

    namespace SSISRUN
    {
        class MyEventListener : DTSRuntime.DefaultEvents
        {
            //自己引用的自定写日志的方法
            private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            public override bool OnError(DTSRuntime.DtsObject source, int errorCode, string subComponent,
              string description, string helpFile, int helpContext, string idofInterfaceWithError)
            {
                //记录Package在运行中出现的错误,以便调试
                log.Info("错误代码:" + source + "<BR>" + "错误组件:" + subComponent + "<BR>" + "错误描叙:" + description + "<BR>");
                return false;
            }
        }
        public class RunSSIS
        {
             //自己引用的自定写日志的方法
            private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            public static  string  Exepackage(string pkgSourse, string ConfigSourse)
            {
                string theResult = "执行SSIS包失败!";
                MyEventListener eventListener = new MyEventListener();
                DTSRuntime.Application app = new DTSRuntime.Application();
                DTSRuntime.Package pkg = app.LoadPackage(pkgSourse, null);//读取包文件(dtsx)
            //DTSRuntime.Package pkg = app.LoadFromSqlServer("ExamplePackage","server_name", "sa", "your_password", null); 从SQL Server加载包
                pkg.ImportConfigurationFile(ConfigSourse);//读取包的配置备件(dtsxConfig)
                //   pkg.Variables["xxx"].Value =xxx 也可用这种方式给Package的变量赋值
                log.Info("开始执行包");
                DTSRuntime.DTSExecResult result = pkg.Execute(null, null, eventListener, null, null);
                log.Info("执行包结果:" + result);

                if(result.Equals(DTSRuntime.DTSExecResult.Success))
                {
                     theResult = "执行SSIS包成功!";
                }
                return theResult;

            }           
        }
    }

  • 相关阅读:
    数据结构问题总结
    基础dp问题总结
    搜索问题总结
    二分+贪心check问题总结
    基础图论问题总结
    数学问题总结
    匹配与网络流学习笔记(在学习中)
    我的第一篇题解
    python+Sqlite+Dataframe打造金融股票数据结构
    用Pandas Dataframe来抓取重构金融股票的各种业务&数据形态
  • 原文地址:https://www.cnblogs.com/huangbaixun/p/1203430.html
Copyright © 2011-2022 走看看