title | titleSuffix | description | author | ms.service | ms.subservice | ms.custom | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|
Copy data from DB2 |
Azure Data Factory & Azure Synapse |
Learn how to copy data from DB2 to supported sink data stores by using a copy activity in an Azure Data Factory or Synapse Analytics pipeline. |
jianleishen |
data-factory |
data-movement |
synapse |
conceptual |
06/07/2022 |
jianleishen |
[!div class="op_single_selector" title1="Select the version of Data Factory service you are using:"]
[!INCLUDEappliesto-adf-asa-md]
This article outlines how to use the Copy Activity in Azure Data Factory and Synapse Analytics pipelines to copy data from a DB2 database. It builds on the copy activity overview article that presents a general overview of copy activity.
This DB2 database connector is supported for the following activities:
You can copy data from DB2 database to any supported sink data store. For a list of data stores that are supported as sources/sinks by the copy activity, see the Supported data stores table.
Specifically, this DB2 connector supports the following IBM DB2 platforms and versions with Distributed Relational Database Architecture (DRDA) SQL Access Manager (SQLAM) version 9, 10 and 11. It utilizes the DDM/DRDA protocol.
- IBM DB2 for z/OS 12.1
- IBM DB2 for z/OS 11.1
- IBM DB2 for z/OS 10.1
- IBM DB2 for i 7.3
- IBM DB2 for i 7.2
- IBM DB2 for i 7.1
- IBM DB2 for LUW 11
- IBM DB2 for LUW 10.5
- IBM DB2 for LUW 10.1
Tip
DB2 connector is built on top of Microsoft OLE DB Provider for DB2. To troubleshoot DB2 connector errors, refer to Data Provider Error Codes.
[!INCLUDE data-factory-v2-integration-runtime-requirements]
The Integration Runtime provides a built-in DB2 driver, therefore you don't need to manually install any driver when copying data from DB2.
[!INCLUDE data-factory-v2-connector-get-started]
Use the following steps to create a linked service to DB2 in the Azure portal UI.
-
Browse to the Manage tab in your Azure Data Factory or Synapse workspace and select Linked Services, then click New:
:::image type="content" source="media/doc-common-process/new-linked-service.png" alt-text="Screenshot of creating a new linked service with Azure Data Factory UI.":::
:::image type="content" source="media/doc-common-process/new-linked-service-synapse.png" alt-text="Screenshot of creating a new linked service with Azure Synapse UI.":::
-
Search for DB2 and select the DB2 connector.
:::image type="content" source="media/connector-db2/db2-connector.png" alt-text="Screenshot of the DB2 connector.":::
-
Configure the service details, test the connection, and create the new linked service.
:::image type="content" source="media/connector-db2/configure-db2-linked-service.png" alt-text="Screenshot of linked service configuration for DB2.":::
The following sections provide details about properties that are used to define Data Factory entities specific to DB2 connector.
The following properties are supported for DB2 linked service:
Property | Description | Required |
---|---|---|
type | The type property must be set to: Db2 | Yes |
connectionString | Specify information needed to connect to the DB2 instance. You can also put password in Azure Key Vault and pull the password configuration out of the connection string. Refer to the following samples and Store credentials in Azure Key Vault article with more details. |
Yes |
connectVia | The Integration Runtime to be used to connect to the data store. Learn more from Prerequisites section. If not specified, it uses the default Azure Integration Runtime. | No |
Typical properties inside the connection string:
Property | Description | Required |
---|---|---|
server | Name of the DB2 server. You can specify the port number following the server name delimited by colon e.g. server:port .The DB2 connector utilizes the DDM/DRDA protocol, and by default uses port 50000 if not specified. The port your specific DB2 database uses might be different based on the version and your settings, e.g. for DB2 LUW the default port is 50000, for AS400 the default port is 446 or 448 when TLS enabled. Refer to the following DB2 documents on how the port is configured typically: DB2 z/OS, DB2 iSeries, and DB2 LUW. |
Yes |
database | Name of the DB2 database. | Yes |
authenticationType | Type of authentication used to connect to the DB2 database. Allowed value is: Basic. |
Yes |
username | Specify user name to connect to the DB2 database. | Yes |
password | Specify password for the user account you specified for the username. Mark this field as a SecureString to store it securely, or reference a secret stored in Azure Key Vault. | Yes |
packageCollection | Specify under where the needed packages are auto created by the service when querying the database. If this is not set, the service uses the {username} as the default value. | No |
certificateCommonName | When you use Secure Sockets Layer (SSL) or Transport Layer Security (TLS) encryption, you must enter a value for Certificate common name. | No |
Tip
If you receive an error message that states The package corresponding to an SQL statement execution request was not found. SQLSTATE=51002 SQLCODE=-805
, the reason is a needed package is not created for the user. By default, the service will try to create the package under the collection named as the user you used to connect to the DB2. Specify the package collection property to indicate under where you want the service to create the needed packages when querying the database. If you can't determine the package collection name, try to set packageCollection=NULLID
.
Example:
{
"name": "Db2LinkedService",
"properties": {
"type": "Db2",
"typeProperties": {
"connectionString": "server=<server:port>;database=<database>;authenticationType=Basic;username=<username>;password=<password>;packageCollection=<packagecollection>;certificateCommonName=<certname>;"
},
"connectVia": {
"referenceName": "<name of Integration Runtime>",
"type": "IntegrationRuntimeReference"
}
}
}
Example: store password in Azure Key Vault
{
"name": "Db2LinkedService",
"properties": {
"type": "Db2",
"typeProperties": {
"connectionString": "server=<server:port>;database=<database>;authenticationType=Basic;username=<username>;packageCollection=<packagecollection>;certificateCommonName=<certname>;",
"password": {
"type": "AzureKeyVaultSecret",
"store": {
"referenceName": "<Azure Key Vault linked service name>",
"type": "LinkedServiceReference"
},
"secretName": "<secretName>"
}
},
"connectVia": {
"referenceName": "<name of Integration Runtime>",
"type": "IntegrationRuntimeReference"
}
}
}
If you were using DB2 linked service with the following payload, it is still supported as-is, while you are suggested to use the new one going forward.
Previous payload:
{
"name": "Db2LinkedService",
"properties": {
"type": "Db2",
"typeProperties": {
"server": "<servername:port>",
"database": "<dbname>",
"authenticationType": "Basic",
"username": "<username>",
"password": {
"type": "SecureString",
"value": "<password>"
}
},
"connectVia": {
"referenceName": "<name of Integration Runtime>",
"type": "IntegrationRuntimeReference"
}
}
}
For a full list of sections and properties available for defining datasets, see the datasets article. This section provides a list of properties supported by DB2 dataset.
To copy data from DB2, the following properties are supported:
Property | Description | Required |
---|---|---|
type | The type property of the dataset must be set to: Db2Table | Yes |
schema | Name of the schema. | No (if "query" in activity source is specified) |
table | Name of the table. | No (if "query" in activity source is specified) |
tableName | Name of the table with schema. This property is supported for backward compatibility. Use schema and table for new workload. |
No (if "query" in activity source is specified) |
Example
{
"name": "DB2Dataset",
"properties":
{
"type": "Db2Table",
"typeProperties": {},
"schema": [],
"linkedServiceName": {
"referenceName": "<DB2 linked service name>",
"type": "LinkedServiceReference"
}
}
}
If you were using RelationalTable
typed dataset, it is still supported as-is, while you are suggested to use the new one going forward.
For a full list of sections and properties available for defining activities, see the Pipelines article. This section provides a list of properties supported by DB2 source.
To copy data from DB2, the following properties are supported in the copy activity source section:
Property | Description | Required |
---|---|---|
type | The type property of the copy activity source must be set to: Db2Source | Yes |
query | Use the custom SQL query to read data. For example: "query": "SELECT * FROM \"DB2ADMIN\".\"Customers\"" . |
No (if "tableName" in dataset is specified) |
Example:
"activities":[
{
"name": "CopyFromDB2",
"type": "Copy",
"inputs": [
{
"referenceName": "<DB2 input dataset name>",
"type": "DatasetReference"
}
],
"outputs": [
{
"referenceName": "<output dataset name>",
"type": "DatasetReference"
}
],
"typeProperties": {
"source": {
"type": "Db2Source",
"query": "SELECT * FROM \"DB2ADMIN\".\"Customers\""
},
"sink": {
"type": "<sink type>"
}
}
}
]
If you were using RelationalSource
typed source, it is still supported as-is, while you are suggested to use the new one going forward.
When copying data from DB2, the following mappings are used from DB2 data types to interim data types used internally within the service. See Schema and data type mappings to learn about how copy activity maps the source schema and data type to the sink.
DB2 Database type | Interim service data type |
---|---|
BigInt | Int64 |
Binary | Byte[] |
Blob | Byte[] |
Char | String |
Clob | String |
Date | Datetime |
DB2DynArray | String |
DbClob | String |
Decimal | Decimal |
DecimalFloat | Decimal |
Double | Double |
Float | Double |
Graphic | String |
Integer | Int32 |
LongVarBinary | Byte[] |
LongVarChar | String |
LongVarGraphic | String |
Numeric | Decimal |
Real | Single |
SmallInt | Int16 |
Time | TimeSpan |
Timestamp | DateTime |
VarBinary | Byte[] |
VarChar | String |
VarGraphic | String |
Xml | Byte[] |
To learn details about the properties, check Lookup activity.
For a list of data stores supported as sources and sinks by the copy activity, see supported data stores.