Linked services and datasets in Azure Data Factory

What a linked service and a dataset are in Azure Data Factory, how they differ, and how one parameterised dataset serves every table instead of one per table.

Short answer: a linked service is a connection: where the source is and how to sign in. A dataset is a named piece of data on that connection: one table, one folder, one file. Activities read and write datasets. Give the dataset parameters and one of them serves every table on the connection.

Most factories that grow messy have the same symptom: a dataset per table, each a copy of the last with one name changed. The fix is to understand which of the two holds what.

How do they fit together?

  1. 1
    Linked servicethe server, the database, how to sign in
  2. 2
    Datasetwhich table or file, with parameters
  3. 3
    Activitya Copy reads one dataset and writes another
  4. 4
    Pipelineruns the activities in order
From a server to the rows a copy reads
QuestionLinked serviceDataset
Where is it?server and databaseno
How do I sign in?managed identity, key or passwordno
Which table or file?noschema and table, or folder and file
Which columns?noan optional schema
How many do I need?one per sourceone per kind of data, with parameters
Which holds what

What does a parameterised dataset look like?

One dataset with two parameters reads any table on the connection:

{
  "name": "SqlTable",
  "properties": {
    "linkedServiceName": { "referenceName": "AzureSqlSales", "type": "LinkedServiceReference" },
    "parameters": { "SchemaName": { "type": "string" }, "TableName": { "type": "string" } },
    "type": "AzureSqlTable",
    "typeProperties": {
      "schema": { "value": "@dataset().SchemaName", "type": "Expression" },
      "table": { "value": "@dataset().TableName", "type": "Expression" }
    }
  }
}

The Copy activity passes the values, usually from a ForEach over a control table: @item().SchemaName and @item().TableName. A new table is then a new row, not a new dataset.

Can a linked service take parameters too?

Yes. A linked service with a DatabaseName parameter reaches several databases on one server, and the dataset passes the value on. Keep secrets out of parameters: point the linked service at Azure Key Vault for passwords and keys, or better, sign in with the factory's managed identity so there is no secret at all.

What goes wrong?

  • A schema imported into a parameterised dataset. A fixed column list on a dataset that reads many tables breaks the mapping for every table but one. Leave the schema empty and let the Copy activity map by name.
  • Connection details in the dataset. Server names belong in the linked service; a dataset that hard-codes them cannot move between development and production.
  • One linked service per environment by hand. Use parameters in the ARM template or deployment, so the same factory points at test or production on release.

Where can you check this?

Where do you start?

Copy every table with one Data Factory pipeline puts the parameterised dataset to work with a control table, and the open course Your first metadata-driven pipeline builds it in your own factory.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.