From time to time people ask how you could compress or extract compressed files in SSIS. While SSIS does not have any built-in taks to do that, you can certainly use execute process task to run a command line using the utility file archiver software of your choice. In the example below, I am using a 7-zip command line to compress a file. 7-zip is open source software (yes, it is free!); but you could use any other tool that provides support for command line.
Notice that the excutable path/file provided in Executable property must exist in any server runing the package (no just in your development environment). Also, remember that most properties of the task can be affected via expressions, that would come handy for changing the path and or file names at run time.
The argument property must be changed to match the proper syntax, depending on your tool of choice.
Loop thru and execute a process task?
ReplyDeleteHow can I loop thru and execute a process task with 7z
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteNever mind i figured it out. Thanks.
ReplyDeleteThanks for the simple explanation – since I’m new to all this, it’s exactly what I needed.
ReplyDeleteHowever, I’m wondering if you have any idea why I cannot email my .zip file using sp_send_dbmail, from an Executie SQL Task? The original file (.xls) emails our just fine, but when I zip the file, I get the following:
[Execute SQL Task] Error: Executing the query "EXEC [msdb].[dbo].[sp_send_dbmail] @profile_name ..." failed with the following error: "Failed to open attachment file 'C:\SQLServer2008…\TheFile.zip'. Access denied.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
I know your post is about zipping a file, but just wondered if you had any suggestions. Thanks!!
ctaylor,
ReplyDeleteI haven't used sp_send_dbmail. Perhaps you should post that in the SQL Server forums
Hi Rafael,
ReplyDeleteI am doing exactly same but I keep getting an error.
The only difference what I'm doing is I am unzipping a gz file.
In the executable I have defined the path to my 7z.exe file and in the argument I have the following:
7z e filename_reviews_*.xml.gz -oc:\FolderName\Vendor
What am I doing wrong? I tried without the 7z, with the 7z. Also, i tried with the executable 7za.exe. nothing works!
Please help.
Thanks,
S
Thannkxx man
ReplyDeleteSlick,
ReplyDeleteDoes the resulting command line from the expression work outside of SSIS? I would double check that the 7zip command is valid in a command line prompt.
Hi Rafael,
ReplyDeleteIn my execute process task,I used sqlcmd.exe to export tables and it runs fine when it is run from "execute package utility" or visual studio but fails when I run it through SQL agent job showing error at working directory of the "execute process task". What could be the issue?
Vivek
Vivek,
ReplyDeleteThere may be a number of reasons that would explain your issue. Most of the time this type of problem is related to permissions. Something to be aware is that the SS agent jobs run under the account running the SS agent service, so check the permissions on that account or create a proxy account.
Thanks Rafeal, its working now ;).
ReplyDeleteI read your many post about SSIS and all of them are simple and useful.
Vivek,
ReplyDeleteI am glad it is working now. Thanks a lot for reading my stuff!
Hi Rafael,
ReplyDeleteI was wondering if you can use variables in the arguments field. What I'm trying is something like : wzunzip -o- -ybc @[SourceFileName] @[DestinationPath]
This field doesn't seem to understand variable replacements.
Thanks
Hi Rafael,
ReplyDeleteCan you tell me how can i set FailTaskIfReturnCodeIsNotSucessValue to False, If I am creating this package and task programmatically using C# ?
Hi Sulaki,
ReplyDeleteIt will work, you have to use expression for the argument and initialize the variable with any value.
Thanks
Vivek
Hi Rafael ,
ReplyDeleteCan you please post the ARGUMENT thati can use to zip the file with password protection
Hi Rafael ,
ReplyDeleteCan you please post the ARGUMENT thati can use to zip the file with password protection in SSIS
Hi Rafael ,
ReplyDeleteWhen i schedule my job which zips and uploads the file, the job runs successfully,but the file is not zipped. Can you please help on this
Hi Rafael, Very good article,
ReplyDeleteA query like that could do to a "script task" to call a Visual Basic control is a control net "NotifyIcon", instead of using a msgbox using a "NotifyIcon" if I pass an error produciera SSIS variable 2008.
Hi Rafael ,
ReplyDeleteI am trying to Zip some XML,XLS files through 7-zip.exe ,generated from ssrs report.
So when there are more number of files generated from report, my package fails ti zip those.I think command line arguements exceeds the maximum length.
So how to handle this scenario.
Thanks
Alok
This comment has been removed by the author.
ReplyDelete