How to Change Database Connection in Power BI
Switching your Power BI report from a test database to a production server can feel like a high-stakes operation. You’ve built the perfect dashboard, every visual is just right, but now you need to point it at live data without breaking everything. This guide will walk you through exactly how to change a database connection in Power BI, from the simple fixes to advanced techniques using parameters that will make future updates a breeze.
Why and When Do You Need to Change a Database Connection?
Before jumping into the "how," it’s helpful to understand the common scenarios where you'll need to update a data source. This isn't a rare task, it’s a normal part of the development lifecycle for any data professional.
You’ll typically need to change your connection when:
- Migrating from Development to Production: This is the most frequent reason. You build and test your reports using a development or staging (UAT) database to avoid impacting live operations. Once approved, you need to repoint the report to the production database before publishing.
- Server Upgrades or Migration: Your IT team might move the company’s SQL Server to a new machine or a cloud service like Azure SQL. When the server name or address changes, all your Power BI reports need to be updated to connect to the new location.
- Database Consolidation: Your organization might merge several databases into one, requiring you to update your source to the new, centralized database.
- Changing Authentication Methods: A security policy update might require you to switch from Windows authentication to a specific SQL Server user account, forcing a change in the connection’s credentials.
Pre-Change Checklist: What to Do First
A little preparation can save you a lot of headaches. Before you touch any settings, run through this quick checklist:
- Back Up Your .PBIX File: This is non-negotiable. Save a copy of your Power BI Desktop file with a name like
MyReport_V1_before_source_change.pbix. If anything goes wrong, you can immediately revert to the working version. - Gather New Connection Details: You can't connect to a server if you don't know where it is. Make sure you have the correct and complete details for the new data source:
- Verify Access: Confirm with your IT or database administrator that you have the necessary permissions to access the new database. There's nothing more frustrating than updating your connection string perfectly, only to be blocked by a "Login failed" error.
Once you’ve got these items squared away, you’re ready to make the switch.
Method 1: The Quick and Easy Way Using Data Source Settings
For most simple database connections (like pointing to a different SQL Server), the easiest method is right inside the Power BI Desktop user interface. This approach works well when your data source type isn't changing - for example, moving from one SQL Server to another.
Here’s the step-by-step process:
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Step 1: Open Data Source Settings
With your Power BI report open, go to the File menu in the top-left corner. From there, select Options and settings > Data source settings.
This opens a window that lists every single data source connection used in your current Power BI file.
Step 2: Select and Change the Source
In the Data source settings window, find and select the database connection you want to change from the list. Once it’s highlighted, click the Change Source... button.
Step 3: Enter the New Server and Database Details
A small dialog box will pop up, showing you the current Server and Database names. This is where you’ll enter the new information you gathered earlier.
- Carefully type the new Server name.
- Type the new Database name (leave this blank if you don't want to specify one initially).
Click OK.
Step 4: Update Credentials if Necessary
Power BI may now prompt you for credentials to connect to the new server. If your old permissions don’t work on the new source, or if the authentication method is different, you’ll need to edit them.
Go back to the Data source settings window, select the source again, but this time click Edit Permissions. In the next window, click Edit... under the credentials section to enter the new username and password or switch the authentication type.
Step 5: Apply Changes and Refresh
After updating the source and permissions, click Close. Back in the main Power BI window, you'll see a yellow banner at the top prompting you to Apply changes. Click it.
Finally, click the Refresh button in the Home ribbon. Power BI will now attempt to pull data from your newly configured source. If everything works, your visuals will reload with the latest data. If you get an error, double-check the server name, database name, and your permissions.
Method 2: Using the Power Query Editor for More Control
Sometimes, the "Change Source" button is grayed out or you need to make more nuanced changes. In these cases, the Power Query Editor is your best friend. This method gives you direct access to the M code that defines a connection.
Here's how to do it:
- In Power BI Desktop, click on Transform data from the Home tab. This will open the Power Query Editor.
- On the right side, in the Query Settings pane, find the APPLIED STEPS section. The very first step is usually named Source. Click the gear icon next to it.
- This will open the same connection dialog box from Method 1, where you can update the server and database details. It's a slightly different path to the same destination.
However, if you want full control, you can edit the M code directly:
Using the Advanced Editor
- With the Power Query Editor open, select the query you want to update from the list on the left.
- Go to the View tab in the ribbon and click on Advanced Editor.
- A new window will appear showing the M code for your query. The first line usually defines the connection. For a SQL Server, it will look something like this:
let
Source = Sql.Database("OldServerName", "OldDatabaseName", [Query="SELECT * FROM Sales"])
in
Source- Simply replace
"OldServerName"and"OldDatabaseName"with your new values:
let
Source = Sql.Database("NewProductionServer", "ProdDatabase", [Query="SELECT * FROM Sales"])
in
Source- Click Done, then Close & Apply in the Power Query Editor. Your report will now pull from the new source.
Best Practice: Use Parameters to Manage Connections Effortlessly
If you find yourself constantly switching between development, testing, and production databases, hardcoding the server name is inefficient and prone to error. The professional approach is to use parameters.
Parameters act as variables for your connections. Instead of changing the M code every time, you just change the parameter's value, and all your queries update automatically. It’s a game-changer for agility.
How to Set Up Connection Parameters
- Open the Power Query Editor (Transform data).
- In the Home tab, click Manage Parameters > New Parameter.
- Create a parameter for the server name. Let’s call it
pServerName. - Now, open the Advanced Editor for your main data query.
- Find the
Sourceline and replace the hardcoded text with your new parameters. It should go from this:
Source = Sql.Database("DEV-SQL01", "Sales_Dev", ...)...to this:
Source = Sql.Database(pServerName, pDatabaseName, ...)- Click Done. Your query is now dynamic!
To switch to your production database, you no longer have to dig into the code. Just go back to Manage Parameters, change the Current Value for pServerName and pDatabaseName to your production details, and hit refresh. It’s clean, simple, and far less risky.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
After Publishing: Managing Connections in the Power BI Service
Changing the source in Power BI Desktop is only half the battle. Once you publish your report to the Power BI Service, you must configure the connection there too, especially if you want scheduled refreshes to work.
This step usually involves an On-Premises Data Gateway if your database is not publicly accessible (i.e., it’s on your company's internal network).
Steps for Power BI Service
- Publish your report from Power BI Desktop.
- Log in to app.powerbi.com and navigate to the workspace where you published the report.
- Find your dataset (it will have the same name as your .PBIX file), click the three dots (...), and select Settings.
- Expand the Gateway and cloud connections section. Your report's data source will be listed here.
- You need to map your dataset's source to a data source that has been configured in your gateway. Make sure a gateway data source exists for your new production database.
- Once mapped, expand the Credentials section and enter the necessary username and password to connect to the database via the gateway.
After saving these settings, your scheduled refreshes will pull data directly from the new production database, keeping your published report up to date automatically.
Final Thoughts
Changing a database connection in Power BI is a fundamental task that can be straightforward or complex depending on your needs. For simple swaps, the built-in Data Source Settings tool is perfect. For more control and future-proofing, using parameters in Power Query is an indispensable best practice that simplifies managing different environments.
All this setup work is the necessary first step before you can even begin analyzing data. At Graphed , we remove this friction entirely. Instead of wrestling with data gateways, connection strings, and credential management, our platform provides instant, one-click integrations with your favorite marketing and sales apps. We handle connecting to your tools like Google Analytics, Shopify, or Salesforce seamlessly, so you can go straight to asking questions in plain English and getting real-time dashboards in seconds.
Related Articles
How to Create Facebook Ads API for Claude Code
Create a Meta Marketing API access token that never expires, using a system user, so Claude Code can pull Facebook ad reports and manage campaigns.
ClickHouse vs Postgres: When to Switch to Columnar
Comparing ClickHouse vs PostgreSQL means matching storage architecture to workload. Row storage wins for transactions. Columnar wins for scan-heavy analytics.
Google Ads for Orthodontists: Get More Booked Consults
Most orthodontic Google Ads campaigns waste money on low-intent searches. The problem is structure, not the platform.