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;

            }           
        }
    }

  • 相关阅读:
    Android组件化路由实践
    RecyclerView实现Gallery画廊效果
    ReactNative实现GridView
    [Java][Servlet] Cannot call sendRedirect() after the response has been committed
    [Java][Servlet] Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
    [Environment Build] Win10下配置Apach Tomcat
    [Java][Liferay] File system in liferay
    [Java][Liferay] 解决在Linux系统中liferay-ext项目无法卸载的问题
    [Coding Style] CSS coding style
    [JQuery] Using skill in JQuery
  • 原文地址:https://www.cnblogs.com/huangbaixun/p/1203430.html
Copyright © 2011-2022 走看看