Showing posts with label SSIS. Show all posts
Showing posts with label SSIS. Show all posts

Thursday, June 6, 2013

SSIS Task: For loop Vs For Each Loop

For Loop


For Loop is used for looping through a number of tasks for a set number of times.


Simply:->  initialize, verify condition, increment\assign


For Each

ForEach Loop loops through various things such as files, objects, ADO connections, etc.

Above screen shot show we have task configured for “Foreach file enumerator” which can be used to move\copy\delete file (of given file) in a given folder


Enumerator configuration:


Folder: Specify the folder path from where we need to process the files


Flies: File name (format) \ file extension





  • Fully qualified: File name along with location is returned .Eg:  C:\Example.txt




  • Name and extension: The file name with its extension is returned.Eg: Example.txt




  • Name only: The file name without its extension is returned.Eg: Example




Variable Mapping



Result of the for loop will be assigned to variable and its value can be used further.





  • Foreach File Enumerator: Enumerates files in a folder




  • Foreach Item Enumeration: Enumerates items in a collection, such as the executables specified in an Execute Process task.




  • Foreach ADO Enumerator: Enumerates rows in a table, such as the rows in an ADO recordset.




  • Foreach ADO.NET Schema Rowset Enumerator: Enumerates schema information about a data source.




  • Foreach From Variable Enumerator: Enumerates a list of objects in a variable, such as an array or ADO.NET DataTable.




  • Foreach NodeList Enumeration: Enumerates the result set of an XML Path Language (XPath) expression.




  • Foreach SMO Enumerator: Enumerates a list of SQL Server Management Objects (SMO) objects, such as a list of views in a database.



Friday, May 24, 2013

SSIS: Derived column : Conditional Operator + Hardcoding Null

Using Conditional Operator In SSIS:

«boolean_expression» ? «when_true» : «when_false»

To hardcode Null : NULL(DT_WSTR, 50)

Following is the expression to get the sub string and compare to "N" and return NULL if true

else the sub string string itself.

(DT_I4)((SUBSTRING(LTRIM(Answer),1,1) == "N") ? NULL(DT_WSTR, 50) : SUBSTRING(LTRIM(Answer),1,1))

Thursday, May 9, 2013

SSIS: Delete Empty Error Log Files With Dynamic Names

Many a times we have a scenario when we have to read from a file write the dirty row into a text file.
In my case, I had to create the text file for each run hence I created a file with dynamic name.
SSIS would create the file even when there is no error.
Now we need to delete the file in case the file is empty i.e. there are no error rows.

As we all know rowcount task come in hand to calculate the no. of records which error out.

ErrorCount
As the name of the error file is dynamic, we use the EvaluateAsExpression property of the variable.
ErrorFilePathEvaluated
As you can see in the screen short above we have a variable name
DataErrorFilePathEvaluated and the property EvaluateAsExpression is set to true. The expression value is set to append datetime to it.

The variable DataErrorFilePathEvaluated is also used as the ConnectionString of the output error file and same is used as the ConnectionString for the file system task to delete the file in case no records error out.

package

Hope it Helps :)

 

Thursday, April 25, 2013

Run Package in 32 Bit\ 64 Bit Mode from Command Prompt

This is an extension to my earlier post

On a 64 bit OS, the default path to the 64 bit would be "c:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTExec.exe"

Still on 64 bit OS, the path to the 32 version would be "c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\DTExec.exe"

Following is the code to run an SSIS package from command prompt:

1. RUN In 32 Bit mode:

[code]
"c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\DTExec.exe" /file C:\PackageFolder\Package.dtsx /CONF C:\ConfigFile.dtsConfig
[/code]

2. RUN In 64 Bit mode:

[code]
"c:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTExec.exe" /file C:\PackageFolder\Package.dtsx /CONF C:\ConfigFile.dtsConfig
[/code]

Monday, April 8, 2013

SSIS Script task: FileNotFoundException: Could not load file or assembly While refering to third party DLL

While referring to a third party DLL in the SSIS Script task we encountered following error:

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target
of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly
'xyzzz, Version=5.3.0.26835, Culture=neutral, PublicKeyToken=5b5f377bc08a4d32' or one
of its dependencies. The system cannot find the file specified.
File name: 'xyzzz, Version=5.3.0.26835, Culture=neutral,
PublicKeyToken=5b5f377bc08a4d32'
at ST_d83cb23ff54e47979cb61222ad9d6b85.csproj.ScriptMain.CreatePdf(String pstrFileName,
String pstrHtml)
at ST_d83cb23ff54e47979cb61222ad9d6b85.csproj.ScriptMain.GeneratePdf(DataSet pobjDs)
at ST_d83cb23ff54e47979cb61222ad9d6b85.csproj.ScriptMain.Main()

Solution: Both the solutions specified work fine. Either of them can be refereed.

Solution 1: Place the xyzzz.DLL to location "C:\Windows\assembly" (this is where the GAC
will place all the files). The file gets INSTALLED there and you need to UNINSTALL to remove it.

Solution 2 (for 32 bit processor): Place the xyzzz.DLL to location "C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn"

Solution 2 (for 64 bit processor): Place the xyzzz.DLL to location "c:\Program Files\Microsoft SQL Server\100\DTS\Binn\"

Hope it Helps :)

Feel free to suggest a better option.

Saturday, March 23, 2013

SSIS: Awesome post by Matt Masson

http://www.mattmasson.com/2013/03/slides-from-ssis-performance-design-patterns-techdays-hong-kong-2013/

SSIS: Remove duplicate rows from input file

We have an requirement in which there are 40,000,000 (forty million) records in the Input file. We have to load it into the databases after implementing a few business logic transformations. Major part of concern is to remove duplicate rows. Following are the possible solutions.

1. Use Sort task and set "remove duplicate" property to TRUE. Would take quite long as it is a full blocking transaction. 

2. Use Script component. Need to compare. I guess it would again be a full blocking transformation. 

3.Dump data to DB and then reload after selecting distinct records. Looks like the best option. 

Will be back with the stats. Feel free to add your suggestions/stats/comments.

Happy SSISing.. :)

Wednesday, March 20, 2013

Executing SSIS Package via command prompt using multiple config files

Normally we have only one config file and this is how we execute the package via command prompt::

[code]/FILE "F:PackageFolder\Package.dtsx" /CONFIGFILE "F:\ConfigFileLocation\FirstPackageConfigFile.dtsConfig" /CHECKPOINTING OFF  /REPORTING EW [/code]

In case we have multiple config files this is how the command goes:

[code]/FILE "F:PackageFolder\Package.dtsx" /CONFIGFILE "F:\ConfigFileLocation\PackageConfigFile.dtsConfig" /CONFIGFILE  "F:\ConfigFileLocation\SecondPackageConfigFile.dtsConfig" /CHECKPOINTING OFF  /REPORTING EW [/code]

Hope it helps! :)

Interesting: SSIS - Handling File with multiple number of colums

http://agilebi.com/jwelch/2007/05/08/handling-flat-files-with-varying-numbers-of-columns/

Monday, March 18, 2013

Quick Tips

1. GUID Using SQL Server




You can generate a GUID using SQL Server using the following T-SQL statement:

[code] SELECT newid()[/code]

This statement generates a new GUID and displays it in the output window.

2. Get current time after removing special characters


[code]

SELECT REPLACE(CONVERT(VARCHAR, GETDATE(), 14),':','')

[/code]

Above code will return '221320687' for date '2013-03-19 22:13:20.687'

3. Converting strings to dates in derived column component: SSIS


Convert from yyyymmdd to date data type

4. Cmd Prompt : Shortcuts: ssms, sqlwb - did they confused you yet?


Check following link to clerify:

http://www.silverlighthack.com/post/2008/08/02/sql-server-2008-quick-fact-new-ssms-shortcut.aspx

[code]
(DT_DBTIMESTAMP)(SUBSTRING([date string], 1, 4) + "-" SUBSTRING([date string], 5, 2) + "-" + SUBSTRING([date string], 7, 2))
[/code]

4. difference between look up and merge join -- SSIS


http://consultingblogs.emc.com/jamiethomson/archive/2005/10/21/SSIS_3A00_-A-case-study-of-using-LOOKUPs-instead-of-MERGE-JOINs.aspx

http://beyondrelational.com/modules/2/blogs/106/Posts/14438/ssis-playing-around-with-lookup-and-merge-join.aspx

 

Friday, June 29, 2012

SSIS Package EXCEL Connection Error: Solution

Issue Description:

Package was running fine

Error:

[Connection manager "Dest File"] Error: SSIS Error Code DTS_E_OLEDB_EXCEL_NOT_SUPPORTED: The Excel Connection Manager is not supported in the 64-bit version of SSIS, as no OLE DB provider is available.

Solution:

You have an Excel connection. The package will need to run in 32 bit mode. To enable 32 bit mode, right click the project in the Solution Explorer and go to properties. Under Debugging, set the property Run64BitRunTime to False.

Monday, March 19, 2012

Function to replace all special characters - Sql Sever

[code language="sql"]
CREATE FUNCTION dbo.RemoveSpecialCharacter(@Str NVARCHAR(MAX))
RETURNS NVARCHAR(MAX)
AS
BEGIN

SET @Str = Replace(@str, Char(13), ' ')
--replace all enters with space
SET @Str = Replace(@str, Char(9), ' ')
--replace all tabs with space
SET @Str = Replace(@str, Char(10), ' ')
--replace all line feeds with space

RETURN @Str

END
[/code]

Useful function to be used for data export to excel sheet(Using SSIS) as the "Enter" makes the data to move to next line and the reports gets distoreted.

Monday, January 23, 2012

SSIS Expression To Append Time and Date with File Name Dynamically

Use Following expression to append date and time at the time of package execution with the file name.
[code]
"D:\output\LogFile"
+ (DT_WSTR, 50)(DT_DBDATE)GETDATE()+"#"
+(DT_STR,2,1252)DATEPART("hh",GETDATE())+"-"
+(DT_STR,2,1252)DATEPART("mi" ,GETDATE())+"-"
+(DT_STR,2,1252)DATEPART("ss",GETDATE())
+".txt"
[/code]
Evaluated Expression would look some thing like this:

D:\output\LogFile2012-01-17#12-11-54.txt

Using Variable:

@[User::OutputFileLocation]  : Variable to hold file location

@[User::OutputFileName]  : Variable to hold file name

Expression:
[code]
@[User::OutputFileLocation]
+ @[User::OutputFileName]
+ (DT_WSTR, 50)(DT_DBDATE)GETDATE()+"#"
+(DT_STR,2,1252)DATEPART("hh",GETDATE())+"-"
+(DT_STR,2,1252)DATEPART("mi" ,GETDATE())+"-"
+(DT_STR,2,1252)DATEPART("ss",GETDATE())
+".txt"
[/code]

Hope it Helps :)

BIDS 2008 does not support XML datatype in OLE DB Command




Senario Overview:

We have some SP which expect some XML Type input parameters and also return XML Type parameter.

Having a requirement to insert data in bulk to Database we planned to use SSIS.

Working on the package, I found that SSIS 2008 doesn't supports XML datatypes in OLE DB Command.

Error Details:

Operand type clash: int is incompatible with xml

Operand type clash: int is incompatible with xml

Googled.. and found that the issue has been solved in latest releases .. :)


But, No luck after installing the latest patch.



Found the following work around:

1. Create a new SP and use NVARCHAR(MAX) instead of Input XML Datatypes and call this SP from SSIS ( We could have modified the original though, but preferred avoiding dependencies issues)

2. Call the main SP from the new SP after type casting to XML


Now new issue:

As we have one XML Output datatype . It still went on giving error even after casting to NVARCHAR(MAX)

Finally, NVARCHAR(4000) worked fine.



Not a robust solution but good enuf to full fill our requirements :)