Biml Tutorial Generating a Simple Package


In the previous chapter we saw the tools we can use to write Biml code and the basics of this XML dialect. Now letís get our hands dirty and write some Biml code to generate a package. In this chapter, weíll write Biml that will create a simple staging package.

Creating Connections

The first step is to define the connections. The following Biml script creates two connections: one to the AdventureWorks database and one to the staging database. Make sure the connection strings are valid for your environment.

connection strings

Try typing the Biml elements to find out how the intellisense works. You can download the entire script with the Biml code at the end of this chapter.

The CreateInProject attribute of a connection element specifies if the connection needs to be a project connection manager or not. If it isnít, the connection manager will be added to every package that references it.

The next step is to create the actual package. Here we will transfer the data from the Person.Person table from AdventureWorks to the staging database. First, we need to create the Packages element, followed by a single Package node. Inside the package, we specify the various Tasks inside its own element.

structure of a simple staging package in Biml

The ConstraintMode attribute of the Package element specifies if all of the tasks inside the control flow are by default parallel or linear. We have also added one Execute SQL Task that will truncate the destination table. In this example we used the DirectInput method, but the other options could work as well (from a variable or a file). The content between the DirectInput tags is the actual T-SQL statement that will be executed by the task. In the task, we also need to specify which connection it will use, which is done by specifying Target as the connection name.

Now we need to add a Data Flow. Here, we keep it simple: only one OLE DB Source and Destination. In the source component, we specify the T-SQL statement through DirectInput and the source connection as well. In the destination, we specify the target connection and the table we want to write data to. This is done using the ExternalTableOutput element.

If you do not specify any mappings, Biml will automatically map the columns in the destination using the column names. By default, the OLE DB Destination will use the Fast Load options.

For the data flow, we used the properties AutoAdjustBufferSize and DefaultBufferMaxRows. You can read more about those in the tip Improving data flow performance with SSIS AutoAdjustBufferSize property.

All we need to do is compile the Biml code and let it generate the package. You do this by right-clicking the Biml file and selecting Generate SSIS Packages.

generate ssis packages

The Output window will show when the expansion of the Biml code is complete and the package has been generated:

output window

When opening the package, youíll notice itís like any other SSIS package. There are no signs it has been generated from scratch.

generated package

Of course, manually creating packages by writing Biml code isnít efficient and certainly not faster than creating them yourself in the Visual Studio designer. In the next chapters, we will learn how we can automate this by using BimlScript Ė a mixture of Biml and C# - and metadata.

Additional Information
  • You can download the Biml script from this chapter here.

Comments For This Article

Monday, March 22, 2021 - 10:21:29 AM - Koen Verbeeck Back To Top (88451)
Hi Suzie,

you're right, the script for creating the database is not mentioned in the tip.
This statement should do it:


Sunday, March 21, 2021 - 7:37:17 AM - Suzie Law Back To Top (88449)
Hi - I can't see where the Target db (StagingDemoBIML) is created. Am I missing something?

get free sql tips
agree to terms