April 28, 2017

SSIS: Script Component Asynchronous Transformation

We can configure the SSIS Script component output as a Synchronous or Asynchronous as required. Using the Synchronous setting each input row is processed as it passes through the component, where as Asynchronous setting waits until multiple input rows have been received before processing.

I had to use this when I was integrating two system using SSIS package. The scenario was to send the massive amount of data in a chunk from the source system into the other system in the JSON format. This Asynchronous setting helped to send the data in a limited batch size.

In order to configure in Asynchronous setting, we need to configure Output 0 to be an asynchronous output. Click on Output 0 in the Inputs and outputs and set the Synchronous property to None.



February 6, 2017

Loading Dll from Embedded Resource to SSIS Script Component

1) Add dll file as a reference.
2) Added dll must be saved in the project as a Embedded Resource.
        a) Right click on the added dll file
        b) Build Action -> Embedded Resource
        c) Copy to Output Directory -> Do not Copy


Use the script below:

 static ScriptMain()
    {
        AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    }
    static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        Assembly executingAssembly = Assembly.GetExecutingAssembly();

        if (args.Name.Contains("AddedFile1"))
        {
            if (AddedFile1 == null)
            {
                using (Stream stream = executingAssembly.GetManifestResourceStream("AssemblyName.AddedFile1.dll"))
                {
                    byte[] assemblyRawBytes = new byte[stream.Length];
                    stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
                    IdentityModel = Assembly.Load(assemblyRawBytes);
                }
            }
            return AddedFile1;
        }
        else if (args.Name.Contains("AddedFile2"))
        {
            if (Newtonsoft == null)
            {
                using (Stream stream = executingAssembly.GetManifestResourceStream("AssemblyName.AddedFile2.dll"))
                {
                    byte[] assemblyRawBytes = new byte[stream.Length];
                    stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
                    Newtonsoft = Assembly.Load(assemblyRawBytes);
                }
            }
            return AddedFile2;
        }
        return null;
    }

We can get AssemblyName from the properties of the script component project.

March 14, 2016

SSRS: The version of the report server database is either in a format that is not valid, or it cannot be read. The found version is '162'. The expected version is '147'.

My laptop has 2 SQL Server instances namely SQLServer2008R2 and SQLServer2012. Today I messed up 2008 R2 reporting services when I was trying to configure 2008 R2 Reporting Services using SQLServer2012 Reporting Services Configuration Manager because for some reason 2008R2 Reporting Services Configuration Manager was denying to connect with the 2008R2 reporting server.

When I was trying to open report server through browser it was throwing an error "The version of the report server database is either in a format that is not valid, or it cannot be read. The found version is '162'. The expected version is '147'.". It made me really frustrated. On ReportServer DB, I found a table named [ReportServer].dbo.[ServerUpgradeHistory]. It contains information about the Server Upgrade. I updated 162 to 147 and it worked well.



UPDATE tbl
SET tbl.ServerVersion = '162'
FROM [ReportServer].dbo.[ServerUpgradeHistory] tbl
WHERE UpgradeID = 3

February 16, 2016

Return Date Part from DATETIME - SQL Server

Most of the time we need date part only from datetime format in SQL Server. 

1) Old method
 SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))



2) On SQL Server 2008 and higher
SELECT CONVERT(DATE, GETDATE()) 



Above two methods helps to keep original date format and returns date part only from datetime.

3) If you want in specific date format (US date format)
SELECT CONVERT(CHAR,GETDATE(),101)


February 1, 2016

SSRS Default Date Parameters

Default date value in SSRS will help to provide the date/time range (Start and End Date) as needed. This will help to reduce the report execution time, it also helps end users because they don't need to provide date range every time they run the report.

For Example:

1)Beginning of current month
=DateSerial(Year(Date.Now), Month(Date.Now), 1)

2)End of current month
=DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Month, 1, DateSerial(Year(Date.Now), Month(Date.Now), 1)))

3) Beginning of  last month

=DateAdd(DateInterval.Month, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1))

4) End of last month
=DateAdd(DateInterval.DAY, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1))

5) End of last month 11 PM
=DateAdd(DateInterval.Hour, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1))

Steps:
1) Double click on the date parameters.

2) Click on "Default Values". Select "Specify values" and click on Add Button and then function (fx)


3) Then, provide the formula and click OK.




October 14, 2014

SSRS report header and footer get cut off when exported to word format

Problem: I had an experience of header and footer cut off while printing the exported SSRS report to word format.

According to Riccardo Muti from Microsoft  "The margins in the word document do match those in the report at 2 cm or 0.79 in. However, Word and SSRS treat page headers and footers differently. Word actually positions them inside the page margins, whereas SSRS positions them inside the area that the margins surround. As a result, in Word, the page margins do not control the distance between the top edge of the page and that of the page header (or similarly for the page footer). Instead, Word has separate "Header from Top" and "Footer from Bottom" properties to control those distances. Since RDL does not have equivalent properties, the Word renderer sets these properties to zero."

Reference:
http://connect.microsoft.com/SQLServer/feedbackdetail/view/614558/word-export-sets-margin-top-margin-bottom-to-0mm

I have the solution so far is before printing the report from Word, we have to increase the size of header and footer. This will help to print the report from word format without header and footer cut off.

September 4, 2014

SSRS Alternate Row Color

This post will help to set alternate row background color in SSRS tablix report using an expression.

1) Select the row from tablix then go to properties (Press F4) and then go to expression of background color property.


2) Use this expression:
                                    = IIf(RowNumber(Nothing) Mod 2 = 0, "Silver", "Transparent")

Then, click OK.


Here, RowNumber(Nothing) will work in each row to give row number in sequential order.

(RowNumber(Nothing) Mod 2 means RowNumber(Nothing) will be divided by 0 and it should give remainder as 0 or 1. Then, if condition is used to give the color for its corresponding result.

3) Then, run the report to see the output. You should get something like this.

Hope, this will help you.