Sub topic 8
Setting data source credentials and gateways
This chapter assumes you can build a report in Power BI Desktop and have already published one to a workspace. It also assumes you know that publishing creates a report and a semantic model. Here you will learn why a published semantic model needs its own credentials, how to set them, and when a gateway is required.
Why credentials are a separate step
When you work in Power BI Desktop, the queries in your model run on your computer. They use the Windows or database login you gave Desktop. Those saved logins stay on your machine. They are not inside the .pbix file.
After you publish, the semantic model lives in the Power BI service. The service now runs the queries, and it has no saved logins for your data sources. Until you give it credentials, refresh will fail. Reports can still show the data that was imported at publish time, because that data is stored in the model.
The behavior depends on the storage mode of each table:
| Storage mode | Where data lives | What needs credentials |
|---|---|---|
| Import | Copied into the semantic model | Scheduled and manual refresh |
| DirectQuery | Stays in the source | Every report view, because queries run live |
| Live connection | Stays in an Analysis Services model | The connection itself |
DirectQuery is the case people miss. An unconfigured DirectQuery model can show errors the first time anyone opens the report.
Where to find the settings
- Open the workspace in the Power BI service.
- Find the semantic model (it has a different icon from the report).
- Open its menu and choose Settings.
- Expand Data source credentials and Gateway and cloud connections.
You need to be the owner of the semantic model, or have a workspace role that allows editing it. Viewers and non-owner Contributors cannot change credentials. If you are not the owner, use Take over on the settings page. This makes you the owner, and you can then set credentials. Taking over replaces the previous owner's saved credentials, so you must enter them again.
Credential types and privacy levels
Each data source asks for an authentication method. The available methods depend on the connector.
| Method | Typical use | Notes |
|---|---|---|
| Anonymous | Public web pages and open files | No secret is stored |
| Basic | SQL logins, some web APIs | Username and password are stored by the service |
| Windows | On-premises SQL Server, file shares | Usually needs a gateway |
| OAuth2 | Azure SQL, SharePoint Online, many SaaS sources | Signs in with your Microsoft Entra ID account |
| Key | Azure Blob storage, some APIs | Account key or API key |
OAuth2 tokens belong to the person who signed in. If that person leaves the company, or their password changes, refresh can fail. For shared reports, prefer a service account or a service principal where the source supports it.
There is also a Privacy level setting for each source: Public, Organizational, or Private. It controls whether the engine may send data from one source to another during a query. Mixing a Private source with a Public one can trigger a "firewall" error in Power Query. Set the level to match how sensitive the data really is, not just to make the error go away.
The settings page also has a checkbox, "Report viewers can only access this data source with their own Power BI identities using DirectQuery". Enable it only when you want single sign-on, where each viewer's identity is passed to the source. It is meant for DirectQuery models that rely on row-level security in the source.
When you need a gateway
A gateway is software that lets the Power BI service reach data it cannot reach directly. You need one when the source sits in a network the internet cannot see, such as:
- An on-premises SQL Server.
- A file on a local drive or network share.
- A database in a virtual network without public access.
You do not need one for sources that are reachable from the internet and supported natively, such as Azure SQL Database with public access, SharePoint Online, or a public web API.
Gateway types
| Type | Who it serves | Typical use |
|---|---|---|
| On-premises data gateway (standard mode) | Many users and many services | Shared, production refresh |
| On-premises data gateway (personal mode) | One user, Power BI only | Testing, small personal files |
| Virtual network (VNet) data gateway | Organization, managed by Microsoft | Sources inside an Azure virtual network |
Prefer standard mode for anything others rely on. Personal mode runs under one user's account on one computer. It stops when that computer is off or the user signs out, and it supports only Power BI.
How a refresh flows through a gateway
The gateway makes only outbound connections. You do not open inbound firewall ports for it. The credentials you enter in the service are encrypted and sent to the gateway, which decrypts and uses them locally.
Connecting a semantic model to a gateway
- Install the gateway on a machine that can reach the data source. Sign in and register it with your organization.
- In the Power BI service, open the semantic model's settings.
- Under Gateway and cloud connections, find the data source and select a gateway from the list.
- If the data source is not yet defined on the gateway, create the connection. You supply the server name, database name, authentication method, and credentials.
- Choose Apply.
The server and database names in the gateway connection must match the ones in your .pbix file exactly. A difference such as SQL01 versus sql01.contoso.com leaves the source showing as unmatched, and you cannot map it.
Users who build or manage the semantic model must be listed as allowed users on the gateway connection. Without that, the gateway does not appear in their list.
Cloud connections for cloud sources
For cloud sources, you can also create a shared cloud connection in Manage connections and gateways. Several semantic models can then reuse one connection and one set of credentials. When the password rotates, you update it in one place. This is the better option when many models use the same Azure SQL database, for example.
Checking the credentials work
After you set credentials, check them before relying on a schedule.
- In the semantic model menu, choose Refresh now.
- Open Refresh history from the same menu.
- Confirm the status is Completed. If it says Failed, open the details and read the error text.
You can also check refresh history from PowerShell. This uses the same module you installed for publishing:
Connect-PowerBIServiceAccount
$ws = Get-PowerBIWorkspace -Name 'Sales Analytics'
$ds = Get-PowerBIDataset -WorkspaceId $ws.Id | Where-Object Name -eq 'Sales'
$url = "groups/$($ws.Id)/datasets/$($ds.Id)/refreshes?`$top=5"
Invoke-PowerBIRestMethod -Url $url -Method Get | ConvertFrom-Json | Select-Object -ExpandProperty valueThe call returns the five most recent refreshes, with status, start time, and end time. Failed rows include an error object.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| "Credentials are not valid" or "Invalid credentials" | Wrong password, expired OAuth token, or locked account | Edit the credentials and sign in again |
| Data source shows a warning icon and cannot be edited | The source is on a private network and no gateway is mapped | Map a gateway connection |
| "The gateway is offline" | Gateway service stopped, machine off, or no outbound access | Restart the service and check network rules |
| Refresh works in Desktop but fails in the service | Desktop used your local login, or a local file path | Move files to SharePoint or OneDrive, or use a gateway |
| "Data source error: firewall" | Privacy levels conflict across sources | Align privacy levels with how sensitive each source is |
| Refresh fails after a person leaves | Credentials belonged to that person | Take over the model and use a service account |
| Scheduled refresh disabled | Several consecutive failures | Fix the cause, then turn the schedule on again |
Edge cases to plan for
- Parameters in source paths. If a data source is built from a Power Query parameter that a query evaluates at run time, the service may not detect it as a fixed source. Use a static source or the
RelativePathoption for web sources. - Several sources in one model. Each source needs its own credentials, and each may map to a different gateway connection. All on-premises sources in one model must usually go through the same gateway.
- Local files. A path like
C:\Data\sales.xlsxworks only through a gateway whose machine can read it. Storing the file in SharePoint Online removes the need for a gateway. - Rotating secrets. When a password changes at the source, update it in the service immediately. The next scheduled refresh uses the old value and fails.
- Overwriting on republish. Republishing a .pbix with the same name keeps the existing credentials and gateway mapping in most cases. If the data source definition changes, such as a new server name, you must set credentials again.
Exercise
A semantic model imports data from an on-premises SQL Server. You publish it and set the source credentials in the semantic model settings, but the data source still shows a warning and refresh fails with "gateway not found". What are two things to check?
Show answer
First, check that a standard-mode on-premises data gateway is installed, online, and mapped to the semantic model's data source. Second, check that the server and database names in the gateway connection exactly match the ones in the .pbix file, and that your account is on the connection's list of allowed users.
Exercise
Why can a published report still show data after publish, even though no credentials have been set, and what stops working?
Show answer
An import-mode semantic model stores a copy of the data taken when you published, so reports can display it. Without credentials, the service cannot query the source, so manual and scheduled refresh fail and the data stays at the publish-time snapshot. DirectQuery reports would show errors, because they query the source on every view.