Sub topic 7
Adding data sources, setting credentials, and mapping the dataset
This chapter assumes you can build a report in Power BI Desktop with Power Query. It also assumes you have a standard-mode gateway installed and registered, as covered in the previous chapter. You should know what a workspace and a published dataset (semantic model) are.
After installing a gateway, the service still doesn't know which data sources it may reach through that gateway. You close that gap with three steps:
- Add a data source to the gateway.
- Set the credentials the gateway uses for that source.
- Map the published dataset to the gateway.
Most "the gateway is installed but refresh still fails" problems come from one of these steps.
The gateway data source
A gateway data source is a saved definition on the gateway cluster. It stores a connection target and the credentials used to reach it. The connection target is, for example, a SQL Server instance and database. It is not a dataset or a report, and it is created separately from them.
To add one in the Power BI service:
- Open Settings (gear icon), then Manage connections and gateways.
- Select New, then choose On-premises.
- Pick the gateway cluster from the list.
- Enter a Connection name, which is a label you choose.
- Select the Connection type, such as SQL Server.
- Fill in the connection details (server and database for SQL Server).
- Choose the Authentication method and enter the credentials.
- Select Create.
The service tests the connection when you save. The test runs on the gateway machine, not in your browser. A successful test therefore proves the gateway can reach the source. It does not prove that the dataset will match it.
Server and database names must match exactly
The service decides which gateway data source a dataset uses by comparing the connection details in the dataset's queries with the data source definitions. The server and database names must match exactly, including how you spell the server name.
Consider this query from a published dataset:
let
Source = Sql.Database("sql01.contoso.local", "Sales"),
Orders = Source{[Schema = "dbo", Item = "Orders"]}[Data]
in
OrdersThe gateway data source must use server sql01.contoso.local and database Sales. These variations will not match it:
| Dataset query uses | Gateway data source uses | Result |
|---|---|---|
| `sql01.contoso.local` | `sql01.contoso.local` | Matches |
| `sql01.contoso.local` | `sql01` | No match |
| `sql01.contoso.local` | `10.0.4.20` | No match |
| `Sales` | `sales_dw` | No match |
If the Desktop file and the gateway disagree, the dataset settings page reports that the gateway cannot map the dataset. The simplest fix is to change the data source definition. If other datasets already depend on that definition, change the dataset in Desktop and republish it.
Keep the names consistent across your team. A common cause of mismatches is one author connecting by short name and another by fully qualified name.
Credentials
Each data source has an authentication method. The available methods depend on the connection type. For SQL Server they include Basic (a SQL login) and Windows (a domain account).
Points to keep in mind:
- The credentials are encrypted before they leave your browser and are stored in the cloud service in encrypted form. Only the gateway can decrypt them, using keys it holds.
- Use a dedicated service account with read-only access to only the needed database. Avoid personal accounts. Refresh breaks when a person changes their password or leaves.
- With Windows authentication, the gateway signs in to the source as that account. The account must be able to log in from the gateway machine.
- Each source in the dataset needs its own data source and credentials. A dataset that reads a SQL Server database and an Excel file on a file share needs two gateway data sources.
Privacy levels
Each data source also has a privacy level: None, Private, Organizational, or Public. It controls whether Power Query may combine data from different sources in one query. If a query merges two sources with incompatible privacy levels, refresh can fail with a "formula firewall" error. Setting the same level on both related sources (usually Organizational for internal data) normally resolves it.
Single sign-on
For some sources you can enable single sign-on, so the gateway queries the source as the signed-in report viewer. That is mostly relevant to DirectQuery and live connections. For scheduled refresh of imported data, the stored credentials are the identity that matters, so this chapter doesn't use single sign-on.
Mapping the dataset to the gateway
Creating the data source does not change the dataset. You must tell the dataset to use the gateway. This is the mapping step.
- In the workspace, find the dataset and open its Settings.
- Expand Gateway and cloud connections.
- Under Gateway connection, switch the toggle to use an on-premises gateway.
- For each data source the dataset uses, choose the matching gateway connection from the drop-down list.
- Select Apply.
If the service finds a data source definition that matches by name, it lists it as available. If a source has no match, the page shows a message that the dataset needs a gateway connection for it, and no gateway appears for that source.
The mapping is stored with the dataset in the service. After you map it once, republishing from Desktop with the same data source details keeps the mapping. Changing the server or database in Desktop breaks it, and you must map again.
What the settings page tells you
| Message or state | Likely cause | What to do |
|---|---|---|
| Gateway not listed | Gateway offline, or you are not allowed to use it | Check the gateway status and your user list on the data source |
| Source "not mapped" | Name mismatch between dataset and data source | Compare server and database exactly |
| Credentials shown as invalid | Password changed or account locked | Edit the data source and re-enter credentials |
| Cannot map to gateway | Dataset has a source the gateway cannot reach, such as a cloud-only source requiring different setup | Review which sources are on-premises |
Who can use a data source
On the data source, the Users tab (or the permissions list in the connections page) controls who may bind datasets to it. A person who publishes a dataset must be listed, or they will not see the connection in the mapping drop-down. Add people or a security group with at least the User role. Only Admin can change the definition.
Verifying the setup
Before you rely on a schedule, test the whole path once:
- In the workspace, choose Refresh now on the dataset.
- Open Refresh history and check that the run ends with Completed.
- If it fails, read the error text. It usually names the data source or the credentials.
For a connectivity check that is independent of Power BI, run this on the gateway machine. It tests outbound traffic to a Service Bus port that the gateway uses:
Test-NetConnection -ComputerName watchdog.servicebus.windows.net -Port 9350TcpTestSucceeded : True means the firewall allows that port. Separately, make sure the gateway machine can reach the source server itself, for example by running Test-NetConnection -ComputerName sql01.contoso.local -Port 1433 for SQL Server's default port.
Common mistakes
- Using
localhostor a short name in Desktop. The gateway resolves names from its own machine, solocalhostpoints to the gateway server itself. Use the same name in the dataset and in the data source, and make sure it resolves from the gateway machine. - Mapping to a personal-mode gateway by accident. Personal mode is configured differently and has no shared data source list. Use a standard gateway for shared datasets.
- Forgetting a source. A dataset with an Excel file on a share and a SQL database needs both mapped. One missing mapping fails the whole refresh.
- Credentials that expire. If an account's password has a rotation policy, schedule a reminder to update the data source. Otherwise refresh fails with a credentials error.
- Dataset owner changes. A dataset's settings are tied to its owner. If someone else must edit them, use Take over on the dataset settings page, then map and confirm credentials again.
Exercise
A dataset's query uses Sql.Database("sql01", "Sales"). The gateway data source was created with server sql01.contoso.local and database Sales, and the connection test succeeded. The dataset settings page still says the dataset cannot use the gateway. What is the problem, and what are two ways to fix it?
Show answer
The server names do not match exactly: sql01 in the dataset versus sql01.contoso.local in the data source. The successful test only shows that the gateway can reach the server. Fix it by either editing the gateway data source (or creating a second one) so the server is sql01, or changing the query in Power BI Desktop to use sql01.contoso.local and republishing the dataset, then mapping it again.
Exercise
A dataset reads from a SQL Server database and from an Excel file on an internal file share, and both are reached through the same standard gateway. How many gateway data sources does it need, and what must you do after creating them?
Show answer
It needs two gateway data sources, one for the SQL Server database and one for the file share, each with its own credentials. After creating them, open the dataset settings, turn on the gateway connection, choose the matching connection for each source, and select Apply. Then run Refresh now to confirm that the history shows Completed.