DEV Community

Josephine Mackylah
Josephine Mackylah

Posted on • Edited on

From Local to Cloud: Lessons I Learned Connecting Power BI to SQL Databases

Introduction.

Data is only as valuable as the insights it provides. Before creating dashboards or writing DAX measures in Power BI, you must first establish a secure connection to your data source. In today's environments, that often means connecting to both on premises SQL Servers and cloud hosted databases, each with its own security requirements. This guide walks you through securely connecting Power BI Desktop to local and cloud SQL databases, including configuring SSL certificates for cloud connections.

Understanding Data Connectivity Modes.

Before building dashboards in Power BI, I learnt that the most important decisions is choosing how Power BI will connect and interact with my SQL database.
Power BI mainly provides two connectivity modes:

  1. Import Mode loads a snapshot of your SQL data into Power BI’s memory. This delivers fast performance and allows you to take full advantage of Power BI’s data modeling and DAX capabilities. However, because the data is stored as a snapshot, regular refreshes are required to keep reports updated.

  2. Direct Query keeps the data within the SQL database and sends live queries whenever users interact with a report. This is useful for very large datasets or situations requiring frequent updates. However, performance depends heavily on the capacity and speed of the underlying database.

Connecting Power BI to a Local SQL Database

When working with a local SQL database, the connection process is usually straightforward because the data environment is within your machine. Before connecting, ensure you have the SQL Server details, database access permissions, and the appropriate authentication credentials.

Gathering Your Database Connection Details

Before connecting Power BI to SQL database, collect the key connection details from the database management tool (such as SSMS or pgAdmin).

You will need:
Server Name: The location or address of your database server (for example, localhost, or an internal network address).
Database Name: The specific database containing the tables you want to analyze.
Authentication Method: The credentials required to access the database, such as Windows/Active Directory authentication or a database username and password.

Initializing the Database Connection

  1. To begin connecting Power BI to a database, open Power BI Desktop and navigate to the Home tab.
  2. Select Get Data, choose More to explore available data sources, then search for a database type (such as SQL Server or PostgreSQL).
  3. Select the appropriate connector and click Connect to start the setup process.

  4. In the database setup window, enter a Server pathway and a Database name.

  5. Select Import and then Click OK.

Authenticate and Load Your Data

  1. A credential prompt will appear. If a database utilizes corporate single sign-on, select Windows -> Use my current credentials. For dedicated SQL logins, select the Database tab and manually type a database user credentials.
  2. Click Connect. If prompted with an unencrypted connection warning, click OK or Run (safe for internal testing environments).
  3. The Navigator window will open. Check the boxes next to the tables you wish to pull, and click Load to commit them to a workspace.

Connecting Power BI to a Cloud SQL Database (Aiven)

Cloud databases such as Aiven PostgreSQL provide scalability and flexibility, but connecting to them requires additional security considerations. Since these databases are accessed over the internet, they rely on encrypted connections to protect data during transmission.
Power BI requires a trusted and secure connection before accessing cloud databases. This means a local machine must recognize and trust the cloud provider’s Certificate Authority (CA) to verify the database server’s identity and establish a secure connection.

Extract Connection Properties from Aiven

Step 1:

  • Download the CA Certificate, Look near the bottom of your image in the Connection information block. Locate the row labeled CA certificate.
  • Click the small Download icon (the arrow pointing down into a tray) located on the far-right side of that row.
  • Save the file to a secure folder on your computer (it will be downloaded as a file typically named ca.pem).

Download and Convert the SSL Certificate

Step 2:

  • Unhide and Copy the Database Credentials. You will also need the correct login credentials shown on this screen to fix the password error from your earlier.
  • Click the Eye icon next to the asterisks in the Password row to reveal your actual password. Copy it.
  • Note the User listed right above it is avnadmin (not postgres like you had earlier).Note the custom Port is 14306 (not 5432).

As a prerequisite, confirm that the PostgreSQL database is available by connecting to it through DBeaver before attempting to connect with Power BI.

Select the dataset you want to import. If your data has already been loaded into the PostgreSQL database, click Load to import the data into Power BI Desktop, and then proceed with data cleaning, data modeling, and dashboarding.

Use the troubleshooting below to identify common connection errors, understand their causes, and implement the appropriate solution.

1. Error Message / Symptom
The remote certificate is invalid according to the validation procedure."
Root Cause Analysis
The Aiven SSL certificate was installed under the Current User certificate store, or it was not registered correctly with the system
Corrective Action
Re-run Phase 2, Step 2.3. Ensure you install the certificate under Local Machine and place it in the Trusted Root Certification Authorities store.

2.Error Message / Symptom
Connection Timeout or "Unable to connect to the remote server"
Root Cause Analysis
A local or corporate firewall is blocking outbound network traffic on Aiven's assigned port.
Corrective Action
Contact your network administrator or IT department to whitelist the outbound traffic for your specific Aiven port, as cloud databases typically use non-standard ports.

3. Error Message / Symptom
An error occurred while reading data from the provider: 'Invalid password
Root Cause Analysis
Incorrect login credentials or cached credentials stored in Power BI's credential manager.
Corrective Action
In Power BI Desktop, go to File →Options and settings → Data source settings. Select your database connection, click Clear Permissions, and reconnect using your correct cloud database credentials.

Final Thoughts and Key Takeaways

-It is easy to get frustrated when a connection gets blocked, but cloud environments like Aiven enforce strict SSL encryption for a reason to keep your data safe. Once you know how to navigate the handshake, it becomes a routine setup rather than a roadblock.

-Remember that Power BI doesn't validate certificates on its own it relies entirely on your local Windows operating system. If you take the extra ten seconds to correctly drop your certificate into the Local Machine's Trusted Root folder, Windows handles the trust automatically behind the scenes.

-The best part about this configuration is that it is a one-time task. Once that secure pipeline is locked in place, you can completely forget about ports and protocols and put 100% of your focus where it belongs: writing clean DAX and designing impactful dashboards.

Top comments (0)