ElyxAI
import export

How to Connect to Database

Excel 2016Excel 2019Excel 365

Learn how to connect Excel directly to external databases like SQL Server, MySQL, or Oracle to import live data without manual copying. This skill enables real-time data analysis, eliminates manual entry errors, and lets you refresh data instantly—essential for business intelligence and large-scale data workflows.

Why This Matters

Database connections automate data retrieval, ensure accuracy, and save hours of manual work—critical for data analysts, financial teams, and enterprise users managing large datasets.

Prerequisites

  • Active database account with connection credentials (server address, username, password)
  • Database driver installed (ODBC driver or native SQL driver)
  • Network access to the database server
  • Basic understanding of SQL queries (optional but helpful)

Step-by-Step Instructions

1

Open Data Tab and Access External Data

Click Data tab > Get & Transform Data > Get Data > From Database (SQL Server Database for SQL, or From Other Sources for MySQL/Oracle).

2

Enter Database Connection Details

Input Server name, Database name, and select either Windows or SQL Server authentication. Enter username and password if required, then click OK.

3

Select Tables or Write SQL Query

Browse available tables in Navigator window, select the table(s) needed, or click Advanced Options to write a custom SQL query for filtered data.

4

Load Data into Excel

Click Load to import data directly into a new worksheet, or Load To to choose specific cell placement or create a pivot table instead.

5

Refresh Connection and Manage Updates

Right-click the imported table > Refresh to update data. Use Data > Queries & Connections to manage, edit, or schedule automatic refreshes.

Alternative Methods

Using Power Query (Advanced)

Data > Get & Transform Data > New Query > From Database allows more granular control over transformations and combines multiple queries before loading.

ODBC Data Source Connection

Set up a system-wide ODBC data source in Windows, then use Data > Get Data > From ODBC for a pre-configured connection without re-entering credentials.

Direct Connection String Method

In advanced scenarios, use VBA or Python scripting to establish connections with custom connection strings for automation and scheduled refreshes.

Tips & Tricks

  • Test your connection with a small query first before pulling large datasets to verify credentials work correctly.
  • Use Data > Queries & Connections pane to view all active database connections and manage them from one location.
  • Enable automatic refresh on Data > Query Options to keep data current without manual updates.
  • Write efficient SQL queries with WHERE and GROUP BY clauses to reduce file size and load times.
  • Store sensitive credentials in Excel's secure connection settings rather than in formulas or VBA code.

Pro Tips

  • Use scheduled refresh in Excel for Microsoft 365 to automatically update your database connection on a set schedule without opening the file.
  • Combine multiple database tables using Power Query's Merge feature to create normalized datasets before loading.
  • Create parameterized queries with Excel cells to filter database results dynamically based on user input.
  • Leverage DirectQuery in Power BI for real-time database connections when Excel's refresh limitations are restrictive.

Troubleshooting

Connection shows 'Access Denied' error

Verify your database user account has SELECT permissions on the target tables. Contact your database administrator to grant appropriate privileges. Test credentials using a database client tool first.

Query runs slowly or times out

Optimize your SQL query by adding WHERE filters, removing unnecessary columns, and using indexes. Consider importing only required data subsets instead of entire large tables.

Refresh fails after moving the workbook

If using file-based connections (DSN), the ODBC source may be unavailable on the new computer. Re-establish the connection or use direct connection strings instead of file DSNs.

Data appears as error values after refresh

Check if source data structure changed (columns deleted/renamed). Update your query and reload, or manually adjust column mappings in the connection properties.

Related Excel Formulas

Frequently Asked Questions

Can I connect to multiple databases simultaneously?
Yes, Excel allows multiple database connections. Each can be managed separately in the Queries & Connections pane. You can merge data from different databases using Power Query.
Will my database credentials be saved in the Excel file?
By default, Excel stores encrypted connection information but not passwords. You can configure settings to prompt for credentials on each refresh for added security, or store them in Windows credential manager.
How often can I refresh database connections?
You can refresh manually anytime, and in Excel 365, set automatic refreshes every 15 minutes to several hours. Frequency depends on your subscription level and database server load.
What databases does Excel support?
Excel supports SQL Server, MySQL, PostgreSQL, Oracle, Access, and any database with an ODBC driver. Native connectors are available for major enterprise databases.
Can I edit the SQL query after importing data?
Yes, right-click the query in Queries & Connections > Edit or go to Data > Queries & Connections > Edit Query to modify the SQL before refreshing.

This was one task. ElyxAI handles hundreds.

Sign up