In our previous article, Getting started with Biml, we have explained what Biml is, what are the related tools and resources and how to get started with this technology. In this article, we will explain how to generate scripts from existing SSIS packages by showing all related options. Then, we will analyze the generated script and identify how each object is mentioned in the script.
Building SSIS package
To run our experiment, we will first build manually an SSIS package that creates a SQL table, read data from a flat-file – where the path is entered as a parameter – and insert it into the created table after adding two derived columns that contain the current date-time and a text value from an SSIS variable.
The SSIS package should contain the following objects:
-
Connection Managers:
- Flat File connection manager (Connection string property is evaluated as an expression)
- OLE DB connection manager
-
Tasks:
-
Execute SQL Task (Execute the command below):
123456789101112CREATE TABLE [dbo].[Person]([BusinessEntityID] [int] NOT NULL,[PersonType] [nchar](2) NOT NULL,[NameStyle] [nvarchar](50) NOT NULL,[Title] [nvarchar](8) NULL,[FirstName] [nvarchar](50) NOT NULL,[MiddleName] [nvarchar](50) NULL,[LastName] [nvarchar](50) NOT NULL,[Suffix] [nvarchar](10) NULL,[EmailPromotion] [int] NOT NULL,[ModifiedBy] [nvarchar](50) NOT NULL,[ModifiedDate] [datetime] NOT NULL) ON [PRIMARY] -
Data Flow Task (Delay Validation = True):
- Flat File Source
- Derived Column Transformation (Contains two column expressions)
- OLE DB Destination
-
-
Parameters:
- FlatFilePath (Type = String, Required = True)
-
Variables:
- Username (Type = String, Value = “Admin”)
- DestinationTable (Type = String, Value= “[dbo].[Person]”)
Figure 1 – Package overview
Convert SSIS Package to Biml
In order to convert an SSIS package into a business intelligence markup language script, you should go to the “Solution Explorer” tab, click on the package and press on “Convert SSIS package to BIML” as shown in the image below (note that BimlExpress should be installed):
Figure 2 – Convert SSIS package option in the context menu strip
After you click on this button, the following form is opened:
Figure 3 – Convert SSIS package form
As you can see, there are many options that we should specify in this form:
- SSIS Asset Location: where we should select where SSIS package is located, there are four types of location available:
- DTProj from File System: The *.dtproj file contains information about project configurations and items such as packages
- ISPAC from File System: The *.ISPAC file is a project deployment file
- DTSX from File System: The *.dtsx file is an SSIS standalone package file (Note that in our case, this option is selected by default as shown above)
- Project from Package catalog: This option is to select a deployed project to an SSISDB database
- Location: This control is to specify the location of the SSIS Asset; it depends on the type of location selected:
- If the location type is a DTProj or ISPAC file, it shows a textbox where the user should select the file path
- If the location type is DTSX file, then it shows a grid where file paths must be added (Note that the file path of the selected package is added by default as shown in the image above)
- If Project from the package catalog is selected, you should specify the connection parameters
- Import Options: This part contains some configuration related to the BIML script that will be generated; they are classified into three categories:
- SSIS Properties to include: where we should select the properties that we need to include within the generated script such as:
- SSIS Names
- SSIS ID’s
- SSIS Annotations
- Package creation metadata
- Merging Into Project: this part contains some project-level configuration such as:
- Import duplicate items
- Source Package Annotation
- Unmapped Column Annotation
- SSIS Version settings: This part contains the following option only:
- Auto Detect SSIS Version
- SSIS Properties to include: where we should select the properties that we need to include within the generated script such as:
In this example, we will not select any of the “SSIS Properties to include” and “Merging Into Project” options, since we are looking to generate a script of a single package object only, and we will leave “Auto Detect SSIS Version” option selected. After finishing configuration, we must click on the “Import” button which will detect the main objects included in this package as shown in the following image:
Figure 4 – Imported package assets
We can reconfigure the import task and click on “Reimport”, or we can select the assets that we need to include within the script from the “Imported Assets” tree view and click on “Add To Project” button to generate the Biml script and add it within the current solution.
Figure 5 – BimlScript1 file added to the solution
Generated Biml Script
In the following section, we will try to analyze the generated Biml script and to illustrate all the objects mentioned, if we open “BimlScript1.biml” file we can see the following script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<Biml xmlns="http://schemas.varigence.com/biml.xsd"> <Connections> <Connection Name="DestinationConnection" ConnectionString="Data Source=.;Initial Catalog=tempdb;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;" /> <FlatFileConnection Name="Flat File Connection Manager" FilePath="F:\SourceFile.txt" FileFormat="Flat File Connection Manager" /> </Connections> <Packages> <Package Name="Package3" Language="None" ConstraintMode="LinearOnSuccess" ProtectionLevel="EncryptSensitiveWithUserKey"> <Variables> <Variable Name="DestinationTable" DataType="String" IncludeInDebugDump="Exclude">[dbo].[Person]</Variable> <Variable Name="Username" DataType="String" IncludeInDebugDump="Exclude">Admin</Variable> </Variables> <Tasks> <ExecuteSQL Name="Execute SQL Task" ConnectionName="DestinationConnection"> <DirectInput>CREATE TABLE [dbo].[Person]( [BusinessEntityID] [int] NOT NULL, [PersonType] [nchar](2) NOT NULL, [NameStyle] [nvarchar](50) NOT NULL, [Title] [nvarchar](8) NULL, [FirstName] [nvarchar](50) NOT NULL, [MiddleName] [nvarchar](50) NULL, [LastName] [nvarchar](50) NOT NULL, [Suffix] [nvarchar](10) NULL, [EmailPromotion] [int] NOT NULL, [ModifiedBy] [nvarchar](50) NOT NULL, [ModifiedDate] [datetime] NOT NULL) ON [PRIMARY] </DirectInput> </ExecuteSQL> <Dataflow Name="Data Flow Task"> <Transformations> <FlatFileSource Name="Flat File Source" LocaleId="None" FileNameColumnName="" ConnectionName="Flat File Connection Manager" /> <DerivedColumns Name="Derived Column"> <Columns> <Column Name="ModifiedBy" DataType="String" Length="5">@[User::Username]</Column> <Column Name="ModifiedDate" DataType="DateTime">GETDATE()</Column> </Columns> </DerivedColumns> <OleDbDestination Name="OLE DB Destination" ConnectionName="DestinationConnection"> <TableFromVariableOutput VariableName="User.DestinationTable" /> </OleDbDestination> </Transformations> </Dataflow> </Tasks> <Connections> <Connection ConnectionName="Flat File Connection Manager"> <Expressions> <Expression ExternalProperty="ConnectionString">@[$Package::FlatFilePath]</Expression> </Expressions> </Connection> </Connections> <Parameters> <Parameter Name="FlatFilePath" DataType="String" IsRequired="true">F:\SourceFile.txt</Parameter> </Parameters> </Package> </Packages> <FileFormats> <FlatFileFormat Name="Flat File Connection Manager" CodePage="1252" TextQualifier="_x003C_none_x003E_" ColumnNamesInFirstDataRow="true" RowDelimiter=""> <Columns> <Column Name="BusinessEntityID" Length="50" DataType="AnsiString" Delimiter="Comma" MaximumWidth="50" /> <Column Name="PersonType" Length="50" DataType="String" Delimiter="Comma" MaximumWidth="50" /> <Column Name="NameStyle" Length="50" DataType="String" Delimiter="Comma" MaximumWidth="50" /> <Column Name="Title" Length="50" DataType="String" Delimiter="Comma" MaximumWidth="50" /> <Column Name="FirstName" Length="50" DataType="String" Delimiter="Comma" MaximumWidth="50" /> <Column Name="MiddleName" Length="50" DataType="String" Delimiter="Comma" MaximumWidth="50" /> <Column Name="LastName" Length="50" DataType="String" Delimiter="Comma" MaximumWidth="50" /> <Column Name="Suffix" Length="50" DataType="String" Delimiter="Comma" MaximumWidth="50" /> <Column Name="EmailPromotion" Length="50" DataType="String" Delimiter="CRLF" MaximumWidth="50" /> </Columns> </FlatFileFormat> </FileFormats> </Biml> |
We can note that there are three main nodes within the scripts:
- Connections: In this node, all created connection managers are defined
- Package: In this node, all variables, parameters, tasks and components defined within the SSIS package are defined
- FileFormats: This node is related to the connections node since it contains all data structure information related to the external files connection managers (such a flat files, since all columns metadata redefined within the connection manager)
The following table contains the XML tag related for each object:
Object Type | XML Tag |
OLE DB Connection manager | <Connection /> |
Flat File Connection manager | <FlatFileConnection /> |
Execute SQL Task | <ExecuteSQL></ExecuteSQL> |
Data Flow Task | <DataFlow></DataFlow> |
Flat File Source | <FlatFileSource></FlatFileSource> |
Derived Column Transformation | <DerivedColumns></DerivedColumns> |
OLE DB Destination | <OleDbDestination></OleDbDestination> |
Variable | <Variable></Variable> |
Parameter | <Parameter></Parameter> |
You can refer to the script above to check the node hierarchy and how tasks and components are linked together.
Conclusion
In this article, we illustrated the BimlExpress Import packages tool and how we can use it to convert existing SSIS projects or standalone packages into Biml scripts. In my opinion, using this tool can be the best way to learn this markup language since it lets you convert SSIS packages and analyze the generated script to see how each object was serialized.
Table of contents
- An overview of SQL Server monitoring tools - December 12, 2023
- Different methods for monitoring MongoDB databases - June 14, 2023
- Learn SQL: Insert multiple rows commands - March 6, 2023