|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, January 10, 2012 4:32 PM
Points: 3,
Visits: 15
|
|
Hi RamaA
Can you please post your mods to use WinRAR. We will be looking to use WinRAR also.
Thanks George
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, March 22, 2013 2:25 AM
Points: 102,
Visits: 151
|
|
Hi George,
In Script Task click on Design Script and Add the Following:
Imports System Imports System.Data Imports System.Math Imports Microsoft.SqlServer.Dts.Runtime Imports System.Data.OleDb Imports System.IO
Public Class ScriptMain
' The execution engine calls this method when the task executes. ' To access the object model, use the Dts object. Connections, variables, events, ' and logging features are available as static members of the Dts class. ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure. ' ' To open Code and Text Editor Help, press F1. ' To open Object Browser, press Ctrl+Alt+J.
Public Sub Main()
Dim InFolder, InFileType, OutFileName, OutExecutable, OutSubject, OutFolder, OutMessage As String Dim FileDate, strDay, strMonth, strYear As String
InFolder = Trim(CStr(Dts.Variables("User::InFolder").Value)) OutFolder = Trim(CStr(Dts.Variables("User::OutFolder").Value)) InFileType = Trim(CStr(Dts.Variables("User::InFileType").Value))
OutFileName = "Filename.zip" 'set this to your desired zip file name OutExecutable = " a -m5 """ + OutFolder + OutFileName + """ """ + InFolder + "*." + InFileType + """" OutSubject = "Attached Zipped Files:- " + OutFileName OutMessage = "Add your message here"
Dts.Variables("User::OutExecutable").Value = OutExecutable Dts.Variables("User::OutFileName").Value = OutFolder + OutFileName Dts.Variables("User::OutSubject").Value = OutSubject Dts.Variables("User::OutMessage").Value = OutMessage
Dts.TaskResult = Dts.Results.Success End Sub
End Class
Please Note:
I have removed the date stamp as it was not needed for me... Also use command prompt to get the desired settings you may need for WinRar. In Command Promt use: C:\Program Files\WinRAR>rar.exe /? to get the list of settings I used: OutExecutable = " a -m5 """ for best compression rate.
------------------------------------------------------------------------------------
In Execute Process Task:
SET Executable: C:\Program Files\WinRAR\Rar.exe
AND SET WorkingDirectory: C:\Program Files\WinRAR
Please let me know if this works for you.
Email: RamaA@za.innovation-group.com
Thanks.
Regards,
Nash
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, April 30, 2013 5:19 PM
Points: 141,
Visits: 388
|
|
Hi, here is the winrar method I use. I posted the 7-zip method previously, to me both are the same, although I prefer the 7-zip method over the winrar method. ' test.rar (is the name of the zip file to be created). ' ..\OUT\ (is the folder on your hard drive where all files with *_20100104.xls exist). ' *_20100104.xls (is the string used in winrar's include statement, only files with _20100104.xls in all subfolders will be included in rar file).
Copy the code below into Script Task of Visual Studio (BIDS).
Imports System.Data.OleDb Imports System.IO Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain Public Sub Main()
Dim InFolder, InFileType, OutFileName, OutExecutable, OutSubject, OutFolder, OutMessage As String Dim FileDate, strDay, strMonth, strYear As String
InFolder = Trim(CStr(Dts.Variables("User::InFolder").Value)) OutFolder = Trim(CStr(Dts.Variables("User::OutFolder").Value)) InFileType = Trim(CStr(Dts.Variables("User::InFileType").Value))
strDay = Right("0" + CStr(Day(Now)), 2) strMonth = Right("0" + CStr(Month(Now)), 2) strYear = CStr(Year(Now)) FileDate = strYear + strMonth + strDay
OutFileName = "Customername" + FileDate + ".rar" OutExecutable = " a -r test.rar ..\OUT\*_20100104.xls """ + OutFolder + OutFileName + """ """ + InFolder + "*." + InFileType + """" OutSubject = "Daily Zipfile:- " + OutFileName OutMessage = "Zip Successful"
Dts.Variables("User::OutExecutable").Value = OutExecutable Dts.Variables("User::OutFileName").Value = OutFolder + OutFileName Dts.Variables("User::OutSubject").Value = OutSubject Dts.Variables("User::OutMessage").Value = OutMessage Dts.TaskResult = Dts.Results.Success
End Sub
End Class
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, April 03, 2013 2:49 AM
Points: 19,
Visits: 53
|
|
Excellent article and very useful, but if you don't write the InFolder with the "\" final you'll receive the zip file empty, I hope this could be helpful for someone who's find the zip file empty.
Bye
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 6:10 AM
Points: 244,
Visits: 981
|
|
| Sandor - what switches did you use to get the WinZip to work?
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, July 22, 2010 9:44 AM
Points: 36,
Visits: 109
|
|
You can also use the one-step method of installing a custom zip task - there are several out there, the first two of them are free (source included) - no scripting or external programs necessary: Compress File - Compresses and decompresses files using System.IO.Compression. TaskUnZip - Manages compressed files (including password protected). Zip - compression and decompression of Zip, GZip, BZip2, Unix (rfc1950) and Tar archives. Zip - Zip Compression / Decompression.
For these and other "one-step" custom tasks, visit the SSIS Community Tasks and Components project on CodePlex.
Todd McDermid - SQL Server MVP, MCSD.Net, MCTS (SQL08BI) Find great SSIS extensions - most are open source - at SSIS Community Tasks and Components Are you doing Data Warehouse ETL with SSIS? Don't use the slow SCD Wizard, use the Kimball Method SCD component instead.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, July 24, 2012 3:15 PM
Points: 8,
Visits: 66
|
|
SSC-Enthusiastic ,
I actually used the WInZip command line tool to do the zipping. I used a Foreach Loop Container to list all the files in a folder, with a VB script inside of it, I created a txt file containing the file names in the folder. Then I pass the filename to WinZip which reads each filename out of the text file and zipps them together. This way, it is fully flexible and automatic. To do this, in the Execute Precess Task, I used an expression for the Argument which builds from to Global Variables: @ZipFileName (also created from other variables to have the current date in it) + @ListFile (the text file containing the files in the folder needed to be zipped). So the actual Variable for the Argument looks like this: @[User::ZipFile] + " @" + @[User::ListFile]. When evaluated it returns 'c:\yourpath\yourzipfile.zip @c:\youpath\yourtextfile.txt'. You can use just this if you are making constant files all the time.
Sandor
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 6:10 AM
Points: 244,
Visits: 981
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, January 02, 2011 11:02 PM
Points: 2,
Visits: 35
|
|
Hi Carolyn
im having a problem with the script, in ssis 2005 it works 100%, as soon as i try it in my 2008 environment it does not find dts.variable object? any idea why this could be? this is the script im using but it does not recognise dts.variable just a note in the script task i have to selcet visual basic 2008 and not .net as it is not available but that shouldnt make a difference.
Imports System Imports System.Data.OleDb Imports System.IO Imports Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim InFolder, InFileType, OutFileName, OutExecutable, OutSubject, OutFolder, OutMessage As String Dim FileDate, strDay, strMonth, strYear As String
InFolder = Trim(CStr(Dts.Variables("User::InFolder").Value)) OutFolder = Trim(CStr(Dts.Variables("User::OutFolder").Value)) InFileType = Trim(CStr(Dts.Variables("User::InFileType").Value))
strDay = CStr(Day(Now)) strMonth = CStr(Month(Now)) strYear = CStr(Year(Now))
If Len(strDay) = 1 Then strMonth = "0" + strDay End If
If Len(strMonth) = 1 Then strMonth = "0" + strMonth End If
FileDate = strYear + strMonth + strDay
OutFileName = "Archive" + FileDate + ".zip" OutExecutable = " a -tzip """ + OutFolder + OutFileName + """ """ + InFolder + "*." + InFileType + """" OutSubject = "Attached Zipped Files:- " + OutFileName OutMessage = "Add your message here"
Dts.Variables("User::OutExecutable").Value = OutExecutable Dts.Variables("User::OutFileName").Value = OutFolder + OutFileName Dts.Variables("User::OutSubject").Value = OutSubject Dts.Variables("User::OutMessage").Value = OutMessage
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, July 24, 2012 3:15 PM
Points: 8,
Visits: 66
|
|
Synergyx,
Use this in SQL 2008:
Imports System Imports System.Data Imports System.Math Imports Microsoft.SqlServer.Dts.Runtime
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _ <System.CLSCompliantAttribute(False)> _ Partial Public Class ScriptMain Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase End Class
Enum ScriptResults Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure End Enum
Public Class ScriptMain
Public Sub Main()
Dim InFolder, InFileType, OutFileName, OutExecutable, OutSubject, OutFolder, OutMessage As String Dim FileDate, strDay, strMonth, strYear As String
InFolder = Trim(CStr(Dts.Variables("User::InFolder").Value)) OutFolder = Trim(CStr(Dts.Variables("User::OutFolder").Value)) InFileType = Trim(CStr(Dts.Variables("User::InFileType").Value))
strDay = CStr(Day(Now)) strMonth = CStr(Month(Now)) strYear = CStr(Year(Now))
If Len(strDay) = 1 Then strMonth = "0" + strDay End If
If Len(strMonth) = 1 Then strMonth = "0" + strMonth End If
FileDate = strYear + strMonth + strDay
OutFileName = "Archive" + FileDate + ".zip" OutExecutable = " a -tzip """ + OutFolder + OutFileName + """ """ + InFolder + "*." + InFileType + """" OutSubject = "Attached Zipped Files:- " + OutFileName OutMessage = "Add your message here"
Dts.Variables("User::OutExecutable").Value = OutExecutable Dts.Variables("User::OutFileName").Value = OutFolder + OutFileName Dts.Variables("User::OutSubject").Value = OutSubject Dts.Variables("User::OutMessage").Value = OutMessage
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
|
|
|
|