The dynamic connection SQL transformation example shows how to dynamically connect to a database based on source file data.
In this example, you have a customer database for the United States, United Kingdom, and Canada. You need to insert customer data from a transaction file into a database based on where the customer is located.
The Expression transformation returns a database connection object name based on the value of the location column. The Expression transformation passes a connection object name to the SQL transformation LogicalConnectionObject port. The SQL transformation connects to the database based on value of the LogicalConnectionObject column.
The following figure shows the Expression transformation and the SQL transformation in a mapping:
The mapping contains the following components:
Customer source definition.
A flat file source definition that includes customer information. The customer location determines which database the SQL transformation connects to when it inserts the customer data.
Error_File target definition.
The target contains a Datastring field that receives database errors from the SQL transformation.
The Expression transformation defines which database to connect to based on the value of the Location column. The Expression transformation returns the connection object name in the Connection port. The connection object is a database connection defined in the Workflow Manager.
. The SQL transformation receives a connection object name in the LogicalConnectionPort. It connects to the database and inserts the customer data in the database.