Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

SSIS foreach Loop - creating dynamic log output files and sending email

$
0
0
Hello All,

I am having a problem in implementing the following scenario:

I have to run scripts against my databases using SSIS package and SQL agent job. This package is deployed on server and a SQL agent job is defined which runs every 5 min.

I want to create dynamic log output files when a particular script is run against my database and if the script fails it needs to send email with the log file attached.

What I have implemented is:

created a foreach loop container -> pointed to pick up *.sql files and then defined a move file system task to move the file to a different folder, to mark it as run.

This is running fine. but want to enhance some more so that I can put in the dynamic log file generation if the script fails and then email that log file to the user.

Any reference or ideas are appreciated !

Present setup:
here is what is set up now and is working fine.

There is a folder for each DB server, under that are the DBs folders.
The script file is dropped in the directory with the Data base name against which the script
will run and the there is a SQL agent job that will pick it up and run it.

Also the file has a .sql extension.
The job kicks off every 20 mins and will check the directory for valid scripts and run them once they are complete it moves the script files to a separate directory.

** I am enhancing this process to include detailed logging for the failed scripts and email the log files to concerned group.
But when implementing rt clk on control flow ->logging -> SSIS log provider for text files --> connection (log.txt). some how it is generating 2 log files. I have defined an expression for that:
"G:\\SSISTest\\ScriptRunner\\Failed\\" +  @[User::filename]   +
(DT_STR,4,1252)DATEPART( "yyyy" , @[System::StartTime]   ) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "mm" ,  @[System::StartTime]  ), 2) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "dd" , @[System::StartTime]   ), 2) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "hh" , @[System::StartTime]   ), 2) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "mi" ,  @[System::StartTime]  ), 2) +
RIGHT("0" + (DT_STR,4,1252)DATEPART( "ss" , @[System::StartTime]   ), 2) +
".txt"

I want the log file as userFilenamedatetime.txt
Note: the userfilename is the file which ran against the db's. meaning it is not defined what the user will name (but it will have .sql extension)

Thanks,

\\K

Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>