Monday 12 December 2011

Linked Server

The Linked Servers option allows you to connect to another instance of SQL Server running on a different machine, perhaps remotely in a different city/country. This can be useful if you need to perform distributed queries (query a remote database). Setting up a linked server is quite straight forward in SSMS(Sql Server Management Studio), all you need is details of the remote server, and the database that you need to query.


Creating Linked Server :-
  1. Click Start, click All ProgramsMicrosoft SQL Server 2008 R2, and then click SQL Server Management Studio.
  2. In the Connect to Server dialog box, specify the name of the appropriate SQL Server, and then click Connect.
  3. In SQL Server Management Studio, double-click Server Objects, right-click Linked Servers, and then click New Linked Server.



  4. In the New Linked Server dialog box, on the General page, in Linked server, enter the full network name of the SQL Serveryou want to link to.


  5. Under Server Type ,Click Other Data Source(Sql Server This is server to server  access Purpose).
    • Linked Server:   Insert the reference name for this linked server. It’s preferable to use a name without spaces in order to avoid problems when using it in an SQL statement.                         
    • Provider Name: Select Micro Soft OLEDB  Provider for Analysis Service if you are trying to connect to the cube.               
    • Product Name: Insert the name of OLE DB data source to add as linked server.                   
    • Data Source: Insert the IP address of your Analysis Service or the name of a data server    
    • Provider String: Insert the connection string with the necessary parameters.
  6. Select Security Tab.Choose Security Type
  7. You will need to map a local server login to a remote server login. On the right side of the Security page, click the Add button. 
     8.Select Server Option Tab .
                    Set the Rpc and Rpc Out parameters to True, and then click OK.
 MSDN Online :  http://msdn.microsoft.com/en-us/library/aa560998(v=BTS.10).aspx




Thanks for Reading......... More to come:)

               


    Saturday 10 December 2011

    Using Conditional Split data Transfer in SSIS 2008

    1. Introduction

    This article uses the Integration Services Conditional Split Data Transformation element to filter and transfer data from a set of flat text files to SQL Server database table. The concept can be easily extended to apply to any other source or destination such as Microsoft Excel. This scenario is useful in creating denormalized database tables in a reporting and analysis situation.

    2. Data Load Task

    Before we start writing any ETL (Extract, Transform and Load) task, we should first layout a rough sketch of the task and sub tasks involved in the package. In this simple tutorial, we are planning to write an ETL package that does the following:
    • Read a set of text files from a folder, each with a common format
    • Separate the records in the files into two groups
    • Load each group into designated destination table
    In this tutorial, we have a set of files that include flower plant names and their types, i.e., Seasonal or Perennial. The files are from different sources but have the same format with a header and data rows. The data elements are comma separated values. The attached compressed file includes a top folder SSISSolution. This folder has two subfolders, i.e., the DataFiles folder containing the two sample data text files and SSISConditionalSplit Visual Studio 2008 solution folder. When you unzip the folder on your local machine, you can open the solution using Visual Studio 2008. However, you will have to update the package for all the connection information based on your SQL Server 2008 installation.

    3. Project Setup

    Open Visual Studio 2008 IDE and setup an SSIS project as shown in the diagram below. After you name the solution, click OK to create the project. The package will be named as Package.dtsx by default. You may rename the package if you wish.

    4. Add Foreach Loop Container on the Control Flow Panel

    Select and drag a Foreach Loop Container control flow element from the toolbox on the left panel of the IDE to the control flow design surface. Rename the element to something meaningful such as "Loop Over Nursery Flower Source". While the control is selected on the design surface, double click on it to open its properties dialog. The dialog is shown in the figure below:
     Next, create a variable to hold the file names iterated in the Foreach Loop Container. Select the "Variable Mappings" on the properties dialog of the loop container and then select the "New Variable" item from the combo drop down as shown in the figure below:
    Now, in the new variable dialog shown below, specify the variable container scope as Package and name the variable as vSourceFile, namespace as User and type as String and click ok on both dialogs to return to the control flow surface.


    5. Create Flat File Source Connection Manager

    In this example, the source of our data are a set of text files in a folder and the destinations are SQL Server 2008 tables. Right click on the connection managers pane on the IDE and choose the "New Flat File Connection...". The Flat File Connection Manager dialog opens as shown in the figure below:
     Specify the entries as shown.
    • Connection Manager Name
    • File Name
    • Header row delimiter as Comma{,}
    • Select the check box to use the column names in the first row
    All other entries you can leave as default. Note that even if connection will execute within the loop container to use a different file in each loop, you can still specify one file. As you will see below, you need to configure the expression of the flat file connection manager to point to the Foreach Container Loop variable we have already created.
    Now, you need to create an expression for the connection string of the Flat File Connection Manager to point to the file variable of the Foreach Loop Container. Select the Flat File Connection Manager you just created and then go the properties pane in the solution explorer and click the "..." button across the expression entry on the properties tree view. This will open the Property Expression Editor dialog as shown below. Select the "Connection String" entry in the left combo box.
     Now, click the "..." button for the Expression Builder dialog as shown below. Select the file variable and specify the expression as shown in the dialog and click Ok to close the dialog. This will bind the variable to the connection manager.


    6. Create SQL Server Database Destination Connection Manager

    Right click the connection manager pane and select "New ADO.Net Connection" entry. On the dialog that opens, click the "New.." button to open the Connection Manager dialog and make selections as shown in the dialog below. Note that the selections of server name and type of connection you specify depends upon the SQL server 2008 you have setup on your local computer.


    7. Add a Data Flow Task to the Foreach Loop Container

    Drag a Data Flow Task from the Control Flow Items pane to the surface of the Foreach Loop Container. Note that this Data Flow Task is a control flow element and will control the execution of the data flow tasks configured on the Data Flow panel. You may also rename the Data Flow Task to something meaningful like "Split Text Data". The control flow surface with the connection manager will look something as shown in the dialog below:

    8. Configure Data Flow

    Now, double click the data Flow Task on the loop container. This will select the Data Flow tab panel on the designer and display the "Data Flow Sources", "Data Flow Transformations" and "Data Flow Destinations" on the tool box pane on the left of the designer. Drag a Flat File Source item from the tool box and place on the Data Flow surface. Double click the Flat File Source to open the properties dialog. Select the Flat File Connection manager you have created in this tutorial in the combo box of the dialog.
    Now, drag a Conditional Split element from the Data Flow Transformations panel to the Data Flow surface and connect the Flat File Source to the conditional split by dragging the green arrow from the Flat File Source to the Conditional Split. Double click the Conditional Split element to open the dialog as shown below:
     On this editor, you will create condition for splitting the data to send to the source. Because the Conditional Split is linked to the source that has the connection to the Flat File Source, you will be able to create condition based on the data. We will create the following two conditions. The fact that we can specify multiple conditions is a powerful visual and computational feature of SSIS. This is extremely useful in reporting and analysis situations.
    • Pick up all perennial flowers
    • Pick up all seasonal flowers
    In the dialog shown above, expand the column names node and drag PlantType column to the table rows below and name the condition and output name as shown in the dialog. This completes the Conditional Split specification. Next we will add the destinations for the two filtered datasets.
    Drag two ADO NET destinations to the Data Flow panel. Rename the destination to something meaningful. Drag the output green arrows from the Conditional Split to the destinations. As you drag the green arrow to the destination, you will be prompted with the following dialog to specify the filter condition for the destination. The dialog is shown below:


    Select the condition you have specified before and click ok. Now, you need to select the destination table. Double click the destination dialog to open the editor. Choose the ADO NET connection manager from the drop down and and the destination table as shown in the dialog below. Optionally, you can go to the Mappings pane on the editor and setup the mappings between the filtered source columns and destination table columns. You can do this by dragging the source column to the mappping table on the lower panel of the editor dialog. Both the views of this destination dialog editor are shown in the figures below:


     The final layout of the data flow pane should look similar to the one shown in the figure below:
     Now, you can run the package in the Visual Studio environment and verify that the two destination tables are populated with the filtered record sets.

    9. Conclusion and Discussion

    This simple tutorial demonstrates the usage of conditional split transfomation in SSIS. The sample can be extended to any source and destination with modifications to connections and split conditions. This feature of the SQL Server 2008 provides powerful mechanism for visually designing ETL packages for reporting, analysis and data warehousing scenarios without writing a single line of code.
    In subsequent articles in this column of Project, I will cover other advanced SSIS data transformation tools and their usage.


    Thanks for reading .. more to come :)

    Wednesday 7 December 2011

    Degenerate Dimension (DD)

    It is a dimension which is derived from fact table. DD doesn’t have separate dimension table. It is mostly used when we planned use transactional level information on the fact table. The main purpose of DD is to provide the info directly without referring other table.

    Primary key of a fact table is subset of table's foreign key. In some cases, we do not need the foreign key in the fact guarantee the uniqueness, in that scenario, DD plays the role.


    Dimension keys without corresponding dimension tables is known as Degenerated Dimensions
     ------------------------------

    That's all , Isn't it  so Simple ?   Lol..  Hope this helps.

    Enjoy

    What is Fact Dimension?

    Sometimes we need to analyze our data based on the some specific value which are available only at fact table. In this case, the particular data will act as a dimension. This dimension is called as Fact Dimension.

    Fact Dimension also known as Degenerated Dimension

    Fact Dimension will be more helpful, when we need to categorize the data based on similar kinds of data.

    Example: Invoice Number, Purchase Order No, Etc.,

    Of course, we can maintain separate dimension table instead of using Fact Dimensions, but no benefit, because the dimension table grow in the same ratio of fact table growth. So by creating Fact dimension, we can avoid duplicate data and reducing memory consumption. Also it helps to improve the performance during data retrieval time.

    SFTP + SSIS

    We had a requirement to work on SSIS package uploading files to SFTP location . Unfortunately SSIS doesn't support SFTP , so we looked around a couple of free SSIS addons which didn't work. Then i finally ended up installing winscp client on machine & used there scripting language  for .Net in to the script component task .


    Code to use :

         Process winscp = new Process();
                winscp.StartInfo.FileName = @"C:\Program Files (x86)\WinSCP\winscp.com";
                winscp.StartInfo.Arguments = "/log=\"" + logname + "\"";
                winscp.StartInfo.UseShellExecute = false;
                winscp.StartInfo.RedirectStandardInput = true;
                winscp.StartInfo.RedirectStandardOutput = true;
                winscp.StartInfo.CreateNoWindow = true;
                winscp.Start();

                // Feed in the scripting commands
                winscp.StandardInput.WriteLine("option batch on");
                winscp.StandardInput.WriteLine("option confirm off");
                winscp.StandardInput.WriteLine("open sftp://username:password@sftp-server-name:portno");
                winscp.StandardInput.WriteLine("ls");
                winscp.StandardInput.WriteLine("put   d:\test.txt " );
                winscp.StandardInput.Close();

                // Collect all output (not used in this example)
                string output = winscp.StandardOutput.ReadToEnd();

                // Wait until WinSCP finishes
                winscp.WaitForExit();

    -------------

    That's all , Isn't it  so Simple ?   Lol..  Hope this helps.

    Enjoy