SSIS basic knowledge - logging, script task & file existence checking

本文详细介绍了如何在SQL Server Integration Services (SSIS) 2012中使用C#代码进行文件存在性检查、控制流程、重命名文件并将其复制到归档文件夹,同时实现日志记录功能。包括使用脚本任务检查文件是否存在,控制流的配置,使用文件系统任务进行文件重命名和复制,以及如何通过日志任务记录关键操作。
摘要由CSDN通过智能技术生成

Task to do :

0.Check the presence of the flat file,if file does exist, go on to 2, or go the end by wring log to physical log file

1. Read a flat file  and bulk insert into to temp table for further processing.

2.rename the file and copy it to archival folder.

 

Knowledge (SSIS 2012, C# codes)

1.File existence checking by using "script  task" . Added variables....Edit script to check file presence

 

C# :

String file  = (String)Dts.Variables["strFileLocation"].Value ;

Dts.Variables["bolFileExists"].Value = System.IO.File.Exists(file);

 

2.Control Flow

 

3.Use "File System Task"  to rename file and copy file

 

4.Enable logging by right-clicking the anywhere  in "Control Flow" editor area

 

5.Edit script task to write specific logging to log file , codes in the main method :

 

int  rowsProcessed = 100;

byte[] emptyBytes = newbyte[0];   

try

            {

                Dts.Log("File doesn't exists!!! " + rowsProcessed.ToString(), 0, emptyBytes);

                Dts.TaskResult = (int)ScriptResults.Success;

           }  

catch (Exception ex)

            { 

//An error occurred.

                Dts.Events.FireError(0, "Script Task Example", ex.Message + "\r" + ex.StackTrace, String.Empty, 0);

 

                Dts.TaskResult = (int)ScriptResults.Failure;

            }

 

 Reference :

scripts taks for logging - http://cimi-digssis.blogspot.sg/2010/05/logging-in-script-task-dtslog.html

rename file : http://www.youtube.com/watch?v=pQHCkPETmoo

File existence : http://www.bidn.com/blogs/DevinKnight/ssis/76/does-file-exist-check-in-ssis

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值