• [译]Stairway to Integration Services Level 12


    介绍

    本文中,我们将结合之前学习的时间冒泡,日志记录,以及复制模型.建立一个自定义的SSIS包日志模型.

    SSIS Task事件回顾    Reviewing SSIS Task Events

    在做实验之前我们更改一下 Precedence.dtsx SSIS 包的设置. 把 Precedence.dtsx SSIS 包的 DisableEventHandlers 属性改为True

    image

    Figure 2

    屏蔽内置日志   Disable Built-In Logging

    首先我们要移除已经存在的日志配置.点击SSIS 下拉菜单然后点击 Logging :

    image
    Figure 7

    Configure SSIS Logs 显示以后点击Delete 按钮删掉之前的文本日志配置 . 

    image
    Figure 8

    从技术上来说,刚才的步骤做了以后.日志就不会记录了. 不过我有洁癖,所以把Containers这边的复选框也取消选择了

    image

    Figure 9

    同样的可以把 file connection manager 也删掉

    image
    Figure 10

    我们把Level 11配置的东西都删掉. 执行一下包,没问题就继续下面操作.

    事件冒泡回顾  Event Bubbling, a Review

    这里省略不翻译了,有需要的朋友可以看之前的章节

    [译]Stairway to Integration Services Level 10 - 高级事件活动

    父子模型日志记录的准备  Preparing for Parent-Child SSIS Design Pattern Logging

    首先我们需要一个数据库和表来记录日志. 先创建一个名为 “SSISStairwayConfig”数据库. 代码如下:

    Use master
    go
    
    /* SSISStairwayConfig database */
    If Not Exists(Select name
                  From sys.databases
                  Where name = 'SSISStairwayConfig')
     begin
      print 'Creating SSISStairwayConfig database'
      Create Database SSISStairwayConfig
      print 'SSISStairwayConfig database created'
     end
    Else
     print 'SSISStairwayConfig database already exists.'
    print ''
    go

    Listing 1

    接着创建 “lg” schema 和“SSISErrors” 表:

    Use SSISStairwayConfig
    go
    /* log schema */
    If Not Exists(Select name
                  From sys.schemas
                  Where name = 'lg')
     begin
      print 'Creating lg schema'
      declare @sql varchar(100) = 'Create Schema lg'
      exec(@sql)
      print 'Lg schema created'
     end
    Else
     print 'Lg schema already exists.'
    print ''
    /* lg.SSISErrors table */
    If Not Exists(Select s.name + '.' + t.name
                  From sys.tables t
                  Join sys.schemas s
                    On s.schema_id = t.schema_id
                  Where s.name = 'lg'
                    And t.name = 'SSISErrors')
     begin
      print 'Creating lg.SSISErrors table'
      Create Table lg.SSISErrors
      (
        ID int identity(1,1)
         Constraint PK_SSISErrors Primary Key Clustered
       ,ErrorDateTime datetime Not Null
         Constraint DF_logSSISErrors_ErrorDateTime
          Default(GetDate())
       ,ErrorDescription varchar(max) Null
       ,ErrorCode int Null
       ,SourceName varchar(255) Null
      )
      print 'Lg.SSISErrors created'
     end
    Else
     print 'Lg.SSISErrors table already exists.'
    print ''

    Listing 2

    记录父子SSIS设计日志      Applying the Parent-Child SSIS Design Pattern to Logging

    打开Parent.dtsx SSIS 包,然后定位到 OnError 事件处理:

    image
    Figure 18

    脱一个 Execute SQL Task到 OnError 事件处理界面然后与 Script Task 连起来:

    image

    Figure 19

    打开 Execute SQL Task Editor 然后把 ConnectionType 属性改为 ADO.NET :

    image
    Figure 20

    点开 Connection 属性下拉框,点击 “<New connection…>” :

    image
    Figure 21

    点了以后会生成一个新的 ADO.NET Connection Manager 在Connection Managers 标签下面可以看到 :

    image
    Figure 22

    Configure ADO.NET Connection Manager 编辑框:

    image
    Figure 23

    点击New按钮配置一个新的数据连接. 选择我们刚才创建好的数据库

    image


    Figure 26

    点几 OK 按钮关闭 Connection Manager 编辑器,返回Configure ADO.NET Connection Manager 显示如下:

    image
    Figure 27

    数据连接会记录在你的配置文件里面. 以后部署好SSIS包依旧可以使用.

    image
    Figure 28

    在 SQLStatement 属性里面输入以下代码 :

    Insert Into lg.SSISErrors
    (ErrorCode
    ,ErrorDescription
    ,SourceName)
    Values
    (@ErrorCode
    ,@ErrorDescription
    ,@SourceName)

    Listing 3

    这个我们创建的插入语句包含了三个参数 : ErrorCode, ErrorDescription, and SourceName.  点击parameter mapping 也来映射变量,点击Add按钮,配置如下图:

    image

    Figure 30

    System::ErrorCode SSIS 变量的类型为 Int32 (integer) 与插入语句中的 @ErrorCode 参数映射.

    Direction 包含 Input, Output, 和 Return 值.  Data Type 字段包含 ADO.Net 的数据类型 . (这个根据我们之前设置 Connection Type的不同而不同)

    用ADO.Net 而 OLEDB 连接类型是有原因的: 在SQL语句和ADO.Net里面我都可以使用参数名.  而用  OLEDB 的话我不得不在SQL语句里面打上问号 . 而引用参数的时候还得打上编号( 0是第一个问号,1是第二个问号…. ) 我觉得 ADO.Net 语法更清楚.

    再把另外两个参数也映射一下.

    image

    Figure 32

    执行 Parent.dtsx SSIS 包 :

    image

    Figure 33

    验证一下数据库中是否记录了错误 日志

    Use SSISStairwayConfig
    go
    Select *
     From lg.SSISErrors

    Listing 4

    结果如下 :

    image

    Figure 34

    原文链接:

    http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/96657/

    项目文件:

    My_First_SSIS_Project_After_Step_12.rar

  • 相关阅读:
    composer 自动加载
    yii linux 上运行脚本 报PDO连接时,提示 Exception 'yiidbException' with message 'SQLSTATE[HY000] [2005] Unknown MySQL server host
    mac上修改php命令行的路径
    git .gitignore 不生效处理办法
    窗口最大化全屏化的方法
    MFC双缓冲解决图象闪烁[转]
    对话框窗口最大化盖住任务栏问题!OnGetMinMaxInfo,WM_GETMINMAXINFO
    关于二维数组传参做形参[转]
    cvLoadImage,cvCloneImage的内存泄露问题
    LPCTSTR和CString的关系
  • 原文地址:https://www.cnblogs.com/haseo/p/4106358.html
Copyright © 2020-2023  润新知